oracle的约束

添加主键约束 alter table 表名 add constraints 约束名 primary key 列名;
alter table cjbiao1 add constraints zjys1 primary key (xingming);
主键约束值是唯一的,如再插入一条相同主键名的数据,怎插入失败,主键不能为空
修改主键约束  alter table 表名 enable/disable primary key 启用和禁用
重命名主键 alter table 表名 rename constraint zjys1 to zjys2; rename 用于重命名约束,to指向新的名称 。
删除主键约束 alter table 表名 drop primary key;也可以使用 alter table cjbiao1 drop constraint zjys2;


外键约束,即父表中的主键值作为子表中外键的值,子表中的外键值要么为空,要么来自父表的主键值 alter table 子表 add constraint 外键名 foreign key(列名) references 主表 (列名) on delete cascade;
添加on delete cascade 为设置级联删除,当主键的字段删除后,外键字段也删除
当父表中没有找到相应的字段,子表就无法插入数据
修改外键约束  alter table 表名 drop constraint 外键约束名


添加唯一性约束 alter table add constraint 唯一性约束名 unique(列名)可以确保非主键列中不输入重复值,称唯一键列
修改唯一性约束名 alter table 表名 rename constraint 原约束名 to 新约束名
禁用和启用唯一约束名 alter table 表名 disable/enable constraint 约束名称
删除唯一约束 alter table 表名 drop constraint 唯一约束名


检查约束 就是检查这列符不符合自己所定义的条件
添加检查约束 alter table 表名 add constraint 检查约束名 check (定义条件)
例如 alter table cjbiao2 add constraint 检查约束名 check (nianling>=25)
重命名检查约束 alter table 表名 rename constraint 旧约束名 to 新约束名
禁用和启用 alter table 表名 disable/enable constraint 约束名
删除约束 alter table 表名 drop constraint 检查约束名
添加非空约束 alter table 表名 modify 列名 not null
撤销非空约束 alter table 表名 modify 列名 null
添加默认约束 alter table 表名 modify 列名 default '默认约束'    当在表中插入数据,没有指定该列的值,系统会自动采用定义的默认值作为该列的值
删除默认约束 alter table 表名 modify 列名 default null。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值