ORACLE的索引和约束详解
* 如果某个约束只作用于单独的字段,即可以在字段级定义约束,也可以在表级定义约束,但如果某个约束作用于多个字段,
必须在表级定义约束
* 在定义约束时可以通过CONSTRAINT关键字为约束命名,如果没有指定,ORACLE将自动为约束建立默认的名称
定义primary key约束(单个字段)
create table employees (empno number(5) primary key,...)
指定约束名
create table employees (empno number(5) constraint emp_pk primary key,...)
定义primary key约束(多个字段,在表级定义约束)
create table employees
(empno number(5),
deptno number(3) not null,
constraint emp_pk primary key(empno,deptno)
using index tablespace indx
storage (initial 64K
next 64K
)
)
ORACLE自动会为具有PRIMARY KEY约束的字段(主码字段)建立一个唯一索引和一个NOT NULL约束,定义PRIMARY KEY约束时可以为它的索引
指定存储位置和存储参数
alter table employees add primary key (empno)
alter table employees add constraint emp_pk primary key (empno)
alter table employees add constraint emp_pk primary key (empno,deptno)
not null约束(只能在字段级定义NOT NULL约束,在同一个表中可以定义多个NOT NULL约束)
alter table employees modify deptno not null/null
unique约束
create table employees
( empno number(5),
ename varchar2(15),
phone varchar2(15),
email varchar2(30) unique,
deptno number(3) not null,
constraint emp_ename_phone_uk unique (ename,phone)
)
alter table employees
add constraint emp_uk unique(ename,phone)
using index tablespace indx
定义了UNIQUE约束的字段中不能包含重复值,可以为一个或多个字段定义UNIQUE约束,因此,UNIQUE即可以在字段级也可以在表级定义,
在UNIQUED约束的字段上可以包含空值.
foreign key约束
* 定义为FOREIGN KEY约束的字段中只能包含相应的其它表中的引用码字段的值或者NULL值
* 可以为一个或者多个字段的组合定义FOREIGN KEY约束
* 定义了FOREIGN KEY约束的外部码字段和相
相关文档:
用户名与口令相同使得口令易于记忆和猜测,但口令也容易被破译,因此作为数据库管理员应该及时检查用户的设置,避免用户名与口令相同,消除不安因素。
创建查询子程序:
SQL> create or replace procedure sys.find_the_same as
hex_password varchar2(30);
trans_password varchar2(30);
v_username varchar2(30); ......
--变量赋值
declare
identity :=0;
a varchar2(59,0);
b varchar2(50):='abc';
a :='cba';
-- 控制语句
----------------------------------
if a>b then
  ......
大块,优点:
1、顺序读、索引读性能好
因为大块容纳的行相对小块数据
多,在进行全表扫描的时候,或者索引扫描的时候,所需要的物理读、逻辑读都要少。
它也能减小索引的树高。对于索引访问
的性能有所提高。
2、大块能容纳比较大的行
容纳大行个人理解,一定程度上可以避免行迁移、行链接。减小大行的读取块 ......
刚才在EYGLE的博客中看到一篇帖子,讲的是DELETE的操作流程,很简短,同时也精辟。
===================================================================================
Oracle中,一个Delete操作的流程
删除(DELETE)
1.Oracle读Block到Buffer Cache(如果该Block在Buffer中不存在)
2.在redo log buffer中记录delet ......