MySQL 创建外键的语法
创建外键时这种语法是否正确?
create table department
(
departmentID int not null auto_increment primary key,
name varchar(30)
) type=InnoDB;
create table employee
(
employeeID int not null auto_increment primary key,
name varchar(80),
job varchar(30),
departmentID int not null references department(departmentID)
) type=InnoDB;
Is this syntax correct in creating a Foreign Key?
create table department
(
departmentID int not null auto_increment primary key,
name varchar(30)
) type=InnoDB;
create table employee
(
employeeID int not null auto_increment primary key,
name varchar(80),
job varchar(30),
departmentID int not null references department(departmentID)
) type=InnoDB;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来 MySQL 接受它(不抱怨语法),但实际上并没有创建外键。
要创建此外键,请运行以下命令:
It looks like MySQL accepts it (doesn't complain about the syntax) but the foreign key is not actually created.
To create this foreign key, run this command:
谢谢。!
Thanks.!