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);
时间: 2024-10-12 23:05:03