数据库完整性

参照完整性

references tb_name(index_col_name,...)

[on delete reference option]

[on update reference option]

限制策略\级联策略\置空策略\不采取实施策略

restrict | cascade | set null | no action \\默认策略是restrict

定义与实现完整性约束

use mysql_test;

create table orders

(

  order_id int not null auto_increment,

  order_product char(50) not null,

  order_product_type char(50) not null,  

  cust_id int not null,

  order_date datetime not null,

  order_price double not null,

  order_amount int not null.

  primary key(order_id),

  foreign key(cust_id)

  references cust(cust_id)

  on delete restrict

  on update restrict

)

用户定义的完整性: 非空约束,check约束

命名完整性约束: constraint[symbol]  \\只能给基于表的完整性约束指定名字,无法给基于列的完整性约束指定名字

更新完整性约束: 使用alter table语句更新与列或表有关的各种约束

1)完整性约束不能直接被修改(先删除,再增加).

2)使用alter table语句,可以独立的删除完整性约束,而不会删除表本身(drop table语句删除一个表,则表中所有的完整性约束都会被自动删除).

posted @ 2020-07-28 21:13  吾爱开发~  阅读(138)  评论(0编辑  收藏  举报