•
Constraints enforce rules at the table level.
•
Constraints ensure the consistency and integrity of the database.
•
The following constraint types are valid:
–
NOT NULL
非空
–
UNIQUE
唯一
–
PRIMARY KEY
主键
–
FOREIGN KEY
外键
–
CHECK
校验
•
View a constraint in the data dictionary.
数据字典中查看
•
You can name a constraint or the Oracle server generates a name by using
the SYS_Cn format.
约束命名
•
Create a constraint at either of the following times:
创建约束的时间
–
At the same time as the creation of the table
在创建表的同时
–
After the creation of the table
创建表之后
//Example of a column-level constraint
CREATE TABLE employees(
employee_id NUMBER(6) CONSTRAINT emp_emp_id_pk
约束
名称
PRIMARY KEY,
7rst_name VARCHAR2(20), ...);
//Example of a table-level constraint:
CREATE TABLE employees(
employee_id NUMBER(6),
7rst_name VARCHAR2(20),
job_id VARCHAR2(10) NOT NULL,
CONSTRAINT emp_emp_id_pk PRIMARY KEY (EMPLOYEE_ID
指定
));
评论