数据库系统概论——完整性约束条件设置方法

数据库系统概论——完整性约束条件设置方法

命名子句

格式

constraint <integrity constraint name> <integrity constraint condition>

其中<integrity constraint condition>包括NOT NULLUNIQUEPRIMARY KEYFOREIGN KEYCHECK短语等

示例

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版)

最后

  • 由于博主水平有限,不免有疏漏之处,欢迎读者随时批评指正,以免造成不必要的误解

猜你喜欢

转载自blog.csdn.net/qq_44486439/article/details/107969261