主键约束( primary key ):主键约束在表中定义一个主键来唯一确定表中每一行数据的标识符. (非空,惟一)
创建表加主键:
create table l_categoryinfo (CategoryID varchar2(20),Categoryname varchar2(20),primary key(CategoryID));
增加表主键:
alter table l_productinfo add constraint pk_lentim primary key(Productid);
删除表主键:
alter table l_productinfo drop constraint pk_lentim;
------------------------------------------
外键约束(foreign key):
增加表外键:
alter table productinfo add constraint fk_lentim foreign key(category) references categoryinfo(categoryid);
删除表外键:
alter table productinfo drop constraint fk_lentim;
------------------------------------------
check约束:
alter table table_name add constraint constraint_namecheck(age>=18 and age<=50);
------------------------------------------
unique约束:
alter table table_name add constraint constraint_name unique(column_name);
------------------------------------------
not null约束:
alter table table_name modify column_name not null;
评论回复