主键,:primary key
自增:AUTO_INCREMENT
不为空:NOT NULL,UNIQUE
检查约束:check 检查插入的数据是否符合某一个或者多个约束。
默认:default.
注释:comment
外键约束:
当表创建好后添加外键:
alter table 表名 add constraint foreign key (外键字段名) references 主表 (主表列名)
删除外键:
alter table 表名 drop foreign key 外键名称
示例:在外键数值变化后,被关联的外键信息也会随着外键的主表变化而变化,如果外键表地段信 息被删除,那么关联外键的信息也会被删除。
alter table 表名 add constraint foreign key (外键字段名) references 主表 (主表列名) on update set null on set null
示例:
alter table 表名 add constraint foreign key (外键字段名) references 主表 (主表列名) on update