莫愁前路无知己,天下谁人不识君。。。。
关于oracle几个常用约束知识的简述
上一篇 /
下一篇 2017-05-16 20:31:24
/ 个人分类:数据库知识
比较常用的键
知识:
1.主键约束:条件是非空,且不重复(primary key----pk)
eg:alter table test add constraint ppp primary key(id);
2.check 约束:对一列数据进行限制
eg:alter table test add constraint ppp check(aaa>20);
3.unique约束:给列的数据追加不重复
eg:alter table test add constraint ppp unique(id);
4.默认约束:让此列默认为一定的数据
eg:alter table test add constraint ppp default 1000 for name;
5.外键约束:引用数据必须存在
两个表:dept:id 产品编号; ename 产品名称
emp :id 用户号 ; did 购买产品号
emp的did 引用dept的id
eg:alter table emp add constraint ppp foreign key(did)reference dept(id);
总结:primary key = unique key + not null
一张表只能有一个primary key(多列则叫联合主键),但可以有多个唯一建。
收藏
举报
TAG:
Oracle
知识