Home  >  Article  >  Database  >  Navicatfor Mysql中添加外键方法

Navicatfor Mysql中添加外键方法

WBOY
WBOYOriginal
2016-06-07 15:17:591894browse

环境:NavicatforMysql 8.2 MySQL Sever 5.1 问题:NavicatforMysql中添加外键 解决: 方法一: 使用SQL语句创建外键: alter table 外键表 add constraint 约束名 foreign key(栏位名) references 参照表(外键栏位名) on delete restrict/set null/cascade

环境:NavicatforMysql 8.2 + MySQL Sever 5.1

问题:NavicatforMysql中添加外键

 

解决:

方法一:

使用SQL语句创建外键:

 

alter table 外键表 add constraint 约束名 foreign key(栏位名) references 参照表(外键栏位名) on delete restrict/set null/cascade on update restrict/set null/ cascade;


 

不指定外键的名称,mysql会自动为你创建一个外键名称:

 

alter table 外键表 add foreign key(栏位名) references 参照表(外键栏位名) on delete restrict/set null/cascade on update restrict/set null/cascade;



方法二:

使用图形界面。

选中表------->右键------->设计表------->外键------->填选项。

 

Navicatfor Mysql中添加外键方法


参考资料:

http://blog.163.com/lkm_1986/blog/static/14066525720106702817523/



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn