您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Oracle中表的建立与修改-五种约束

2024/7/24 5:18:44发布34次查看
oracle中包括五种约束,包括主键约束(primary key,该属性的值不能为空,不可重复,默认该列自动建立索引),外键约束(foreign k
表的建立
oracle中包括五种约束,包括主键约束(primary key,该属性的值不能为空,不可重复,默认该列自动建立索引),外键约束(foreign key() references rname,参照完整性约束,该属性的值必须在所对应的关系中存在),非空约束(not null),唯一约束(unique,不可重复,但可以为空,因为在数据库中,该表达式 null=null 的返回结果为unknown),check约束(check(a in(a1,a2,a3))),,如下例
create table r1
( id numeric(15) primary key, //主键约束
name varchar2(15) not null, //非空约束
gender varchar2(2) check(gender in ('m','f','o')), //模拟枚举约束,oracle中不支持枚举类型
stu_number unique, //禁止重复,但可以为空
foreign key(stu_number) references r0); //外键约束
表的修改
1.增加一个新的属性
alter table r add id varchar2(10);
2.减少一个已经存在的属性
alter table r drop name;
3.修改一个已经存在的属性的限制
alter table test1 modify grade number(5,2) not null;
4.修改一个已经存在的属性的属性名称
alter table test1 rename column id to stu_number;
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product