在执行这句时出错:altertableCommentaddconstraint"FK_News-Comment"foreignkey(newsId)referencesNews(newsId)ondeleterestrictonupdaterestrict;显示如下错误:[Err]1064-Youhavea...
在执行这句时出错:
alter table Comment add constraint "FK_News-Comment" foreign key (newsId)
references News (newsId) on delete restrict on update restrict;
显示如下错误:
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"FK_News-Comment" foreign key (newsId)
references News (newsId) on delete' at line 1
[Err] alter table Comment add constraint "FK_News-Comment" foreign key (newsId)
references News (newsId) on delete restrict on update restrict;
不是约束语句的问题,我和其它软件生成的sql语句对比了下,是引号的问题。
改成这样就行了:
alter table `Comment` add constraint `comment_newsId` foreign key (`newsId`)
references `News` (`newsId`) on delete restrict on update restrict;
或者是改成这样:
alter table Comment add constraint FK_News_Comment foreign key (newsId)
references News (newsId) on delete restrict on update restrict;
展开