疯掉了。。。谁来告诉我,这段到底错在哪?

2012-07-07 19:25:00 +08:00
 smoker
CREATE TABLE `users` (
`id` int(11) NOT NULL auto_increment,
`username` varchar(100) NOT NULL,
`password` varchar(35) NOT NULL,
`groupid` int(11) NOT NULL,
`groupname` varchar(100) NOT NULL,
`phone` varchar(35),
`introduction` varchar(255),
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`),
CONSTRAINT FOREIGN KEY ('groupid', 'groupname')
REFERENCES group ('id', 'groupname')
ON DELETE RESTRICT
ON UPDATE CASCADE
)ENGINE=InnoDB DEFAULT CHARSET=utf8;




ERROR 1064 (42000): 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 ''groupid', 'groupname')
REFERENCES group ('id', 'groupname')
ON DELETE RESTRICT
2831 次点击
所在节点    MySQL
5 条回复
fanzeyi
2012-07-07 19:34:57 +08:00
CONSTRAINT FOREIGN KEY (`groupid`, `groupname`)
REFERENCES `group` (`id`, `groupname`)

试试
smoker
2012-07-07 19:35:47 +08:00
沉的好快。。。
那我说明下。。

问题出在

CONSTRAINT FOREIGN KEY ('groupid', 'groupname')
REFERENCES group ('id', 'groupname')
ON DELETE RESTRICT
ON UPDATE CASCADE

这段上,其中group是需要链接的表, id是PRIMARY KEY, groupname是UNIQUE KEY
然后……然后就出错了。。。
smoker
2012-07-07 19:39:57 +08:00
居然成了。。。。谢谢!!!

奇怪明明刚才自己加''了也不行。。。总之复制你这个好了。。
qdvictory
2012-07-07 19:42:17 +08:00
@smoker 那不是'号,而是`号
fanzeyi
2012-07-07 20:01:18 +08:00
@smoker ` 号是 键盘左上角 ESC 下面 1 左边的那个按钮

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/41711

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX