我有一个MySQL数据库:
CREATE TABLE `users votes` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`userid` int(11) NOT NULL,
`forumtopicid` int(11) DEFAULT NULL,
`replyid` int(11) DEFAULT NULL
)
我正在尝试创建两个独特的约束:
CREATE UNIQUE INDEX index_first
ON `users votes`(userid, forumtopicid, replyid)
WHERE forumtopicid IS NOT NULL;
CREATE UNIQUE INDEX index_second
ON `users votes`(userid, replyid)
WHERE forumtopicid IS NULL;
这是一个错误,我不确定如何解决。是否无法为MySQL约束添加WHERE子句?
#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 'WHERE forumtopicid IS NOT NULL' at line 3
答案 0 :(得分:3)
这是正确的 - 你不能在WHERE
语句中使用CREATE INDEX
(在mysql中)。