ON DELETE restrict(约束):当在父表(即外键的来源表)中删除对应记录时,首先检查该记录是否有对应外键,如果有则不允许删除. no action:意思同restrict.即如果存在从数据,不允许删除主数据. cascade(级联):当在父表(即外键的来源表)中删除对应记录时,首先检查该记录是否有对应外键,如果有则也删除外键在子表(即包含外键的表)中的记录. set null:当在父表(即外键的来源表)中删除对应记录时,首先检查该记录是否有对应外键,如果有则设置子表中该外键值为nu…
Messages表: mysql>create table Messages( ->message_id int auto_increment primary key, ->user_name varchar(50) not null, ->author_id int not null, ->body text, ->forum_id int not null); Forums表: mysql>create table Forums( ->forum_id…
主键(PRIMARY KEY) 主键在一个数据表中只能有唯一的一个,约束当前字段的值不能重复,且非空保证数据的完整性,也可以当做当前数据表的标识符用来查询(当做索引,唯一性索引的一种) 创建带主键的表 /*带主键*/ CREATE TABLE T( id int(11) not null primary key, name char(20) ); /*带复合主键*/ CREATE TABLE T( id int(11) not null , name char(20) not null, pri…