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约束的外部码字段和相
相关文档:
Redo Byte Address (RBA)
Recent entries in the redo thread of an Oracle instance are addressed using a 3-part redo byte address, or RBA. An RBA is comprised of
the log file sequence number (4 bytes)
the log file block number (4 bytes)
the byte offset into the block at which the redo record sta ......
用户名与口令相同使得口令易于记忆和猜测,但口令也容易被破译,因此作为数据库管理员应该及时检查用户的设置,避免用户名与口令相同,消除不安因素。
创建查询子程序:
SQL> create or replace procedure sys.find_the_same as
hex_password varchar2(30);
trans_password varchar2(30);
v_username varchar2(30); ......
Inthirties Oracle论坛日独立IP连续一周突破200 http://www.inthirties.com
也许200根本就很少,但是对于inthirties来说,已经是一个很欣慰的事叻。 再接再厉,把Inthirties Oracle论坛办成实用的学习Oracle的论坛。 ......
关于Oracle 10g 归档方式的讨论:关闭归档/启用闪回恢复区归档(Oracle 10g新特性)/启用类Oracle9i的归档
注:在Oracle安装过程中,如果数据库是自动创建的,那么该数据库最初的存档模式是由操作系统指定的。通常情况下,归档日志在Oracle数据库安装结束后需要手工创建。
环境:Oracle 10g 10.2.0.1.0/Windows 2003 ......
语法:
select *
from [TABLE] as of timestamp
to_timestamp('时间', ’时间格式')
作用:
查询某个时间点的数据,在这个时间点之后,数据更改已经提交了。
可以用来更正用户对数据的误操作
可以用来获取数据的更改情况,比如频率等
原理:
当数据update或delete时,原来的数据 ......