資料庫系統概論——完整性限制條件設定方法
命名子句
格式
其中
<integrity constraint condition>
包括
NOT NULL
、
UNIQUE
、
PRIMARY KEY
、
FOREIGN KEY
和
CHECK
短語等
示例
在
department
表中為完整性限制條件命名
create table department
(dept_name varchar(20) constraint c1 not null,
building varchar(15) constraint c2 unique,
budget numeric(12, 2) constraint c3 check(budget >= 10000 and budget <= 100000),
constraint key_constraint primary key (dept_name));
修改子句
格式
使用
ALTER TABLE
語句修改表中的完整性限制限制
alter table <table name>
drop constraint <integrity constrain conditions>;
示例
删除完整性限制條件
删除
department
表中名為
c1
的完整性限制條件
alter table department
drop constraint c1;
修改完整性限制條件
修改
department
表中名為
c1
的完整性限制條件,必須先删除原來的限制條件再增加新的限制條件
alter table department
drop constraint c1;
alter talbe department
add constraint c1 unique not null;
鳴謝
資料庫系統概論(第5版)
資料庫系統概念(原書第6版)
最後
- 由于部落客水準有限,不免有疏漏之處,歡迎讀者随時批評指正,以免造成不必要的誤解