删除列级完整性约束_列级完整性约束条件与表级完整性约束条件有什么不同

2017-06-18 回答

多个表之间有参照完整性约束. check 一般是检查自己这个表的 约束, 例如 什么性别只能是 0/1, 年龄不能大于 100 之类的检查. 多表参照, 一般是使用 外键约束来实现的: 例如: -- 创建测试主表. id 是主键. create table test_main ( id int not null, value varchar(10), primary key(id) ); -- 创建测试子表. create table test_sub ( id int not null, main_id int , value varchar(10), primary key(id) ); -- 插入测试主表数据. insert into test_main(id, value) values (1, 'one'); insert into test_main(id, value) values (2, 'two'); -- 插入测试子表数据. insert into test_sub(id, main_id, value) values (1, 1, 'oneone'); insert into test_sub(id, main_id, value) values (2, 2, 'twotwo'); sql> -- 创建外键(默认选项) sql> alter table test_sub add constraint main_id_cons foreign key (main_id) references test_main; table altered. sql> sql> -- 测试删除主表数据. 将出错 ora-02292: 违反完整约束条件 sql> delete 2 test_main ...多个表之间有参照完整性约束. check 一般是检查自己这个表的 约束, 例如 什么性别只能是 0/1, 年龄不能大于 100 之类的检查. 多表参照, 一般是使用 外键约束来实现的: 例如: -- 创建测试主表. id 是主键. create table test_main ( id int not null, value varchar(10), primary key(id) ); -- 创建测试子表. create table test_sub ( id int not null, main_id int , value varchar(10), primary key(id) ); -- 插入测试主表数据. insert into test_main(id, value) values (1, 'one'); insert into test_main(id, value) values (2, 'two'); -- 插入测试子表数据. insert into test_sub(id, main_id, value) values (1, 1, 'oneone'); insert into test_sub(id, main_id, value) values (2, 2, 'twotwo'); sql> -- 创建外键(默认选项) sql> alter table test_sub add constraint main_id_cons foreign key (main_id) references test_main; table altered. sql> sql> -- 测试删除主表数据. 将出错 ora-02292: 违反完整约束条件 sql> delete 2 test_main 3 where 4 id = 1; delete * error at line 1: ora-02292: integrity constraint (hr.main_id_cons) violated - child record found

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值