关于oracle中对已建表格进行约束的一些操作

//constraint后面的命名可以随意取

//设置固定值用check而不是用default

--添加字段
alter table student add address varchar2(50);

--给student添加主键
alter table student add constraint pk_student_id primary key(id);

--给name添加非空约束
alter table student modify name constraint name_not_null not null;

--给code添加唯一约束
alter table student add constraint code_unique unique(code);

--sex只能是男或女
alter table student add constraint sex_check check(sex='男' or sex='女');

--birthday默认为sysdate
alter table student modify birthday date default sysdate;

--添加外键
alter table student add constraint fk_cl_id foreign key(cl_id) references stclass(cl_id);

猜你喜欢

转载自www.cnblogs.com/demonzql/p/10587008.html