约束

删除约束

alter table 表名 drop constraint 约束名;

1.非空约束

注意非空约束的语句不含有constraint关键字,而是使用modify

修改方式

alter table "表名" modify "列名" not null;

创建方式

create table "表名"("列名1" "数据类型" not null);

2.主键约束

主键自带唯一和非空约束,并且具有主键索引

修改方式

alter table "表名" add constraint "约束名" primary key(列名);

删除主键

alter table "表名" drop constraint "约束名";

建表创建主键

create table "表名"("列名" "数据类型" primary key);

3.唯一约束

修改方式

alter table "表名" add constraint "约束名" unique("列名");

4.外键约束

删除外键

alter table "表名" drop constraint "约束名";

添加外键

alter table "表名" add constraint "约束名" foreign key ("本表列名") references "其他表名"("其他表列名");

6.check约束(正则表达式等)

一般数据完整性检查在前端或者其他程序中就已经检查过了,在这里并不需要检查

chek约束

alter table 表名 
add constraint 约束名
check(一个判断语句,输出是真或者假)

匹配正则表达式

alter table 表名 add constraint 约束名 check( regexp_like(列名,'正则表达式'));

此约束为正则表达式匹配

注意:正则表达式的函数是regexp_like()!!!注意拼写`

你可能感兴趣的:(约束)