当前位置:Gxlcms > 数据库问题 > Mysql外键创建

Mysql外键创建

时间:2021-07-01 10:21:17 帮助过:23人阅读

CREATE TABLE `l1` (
  `nid` int(11) NOT NULL AUTO_INCREMENT,
  `user` char(10) NOT NULL,
  `pwd` char(10) NOT NULL,
  `s1_nid` int(11) NOT NULL,
  PRIMARY KEY (`nid`),
  KEY `l1_s1` (`s1_nid`),
  CONSTRAINT `l1_s1` FOREIGN KEY (`s1_nid`) REFERENCES `s1` (`nid`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

  

删除外键

alter table l1 drop foreign key l1_s1;

  

创建外键

alter table l1 add constraint s1_l1 foreign key (s1_nid) references s1(ni
d);

  

Mysql外键创建

标签:sql   ima   ons   innodb   auto   foreign   key   mysql外键   highlight   

人气教程排行