主键约束: primary key
自动增长: auto_ increment 需要 有主键才行
不重复: unique
非空: not null
默认: default "内容" -----注意 类型
创建 时候 添加 外键约束
create table xxx (id int() ,name () )
create table xxx (id int() , name () , cid int () , foreign key (cid) references 表一名 (id) )
添加 外键约束:
alter table xxaxx add constraint Fk_id foreign key (id ) references xxbxx (id)
-----------------> 给 xx axx 中 id 添加 xxbxx 的 id 外键
alter table xxx add constraint PK_ID primary key (id)
--------------------->添加 主键约束
删除:
alter table xxx drop primary key ------>删除 主键
alter table xxx drop foreign key FK_ID; -------->删除外键 约束
先删除 设置外键 约束 的表 才可以 删除 外键所关联的表
Linux --数据库 约束 命令
最新推荐文章于 2022-02-18 17:52:11 发布