赞
踩
在oracle数据库中,约束分为:主键约束、外键约束、唯一约束、非空约束、检查约束。
(1.1)在创建表的是时候添加主键约束:在创建表的最后添加:(当然,也可以不放在最后,放在定义类的后边,即not null 的后边)
create table src.t1(id number,qq number,constraint pk_t1_id primary key(id));
(1.2)在已有的表上添加主键约束
alter table 表名 add constraints 主键名 primary key (列名);
(1.3)删除主键约束
alter table 表名 drop constraint 主键名;
(2.1)在创建表的时候添加外键约束
create table src.t2(id number,cc number,constraint fk_t2_id foreign key(id) references src.t1(id));
(2.2)在已有表中添加外键约束
alter table 需要添加外键的表名 add constraint 外键名字 foreign key (列名) references 引用表的表名(引用表的列名);
(2.3)删除外键约束
alter table 表名 drop constraint 外键名;
&
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。