MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
smoker
V2EX  ›  MySQL

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

  •  
  •   smoker · Jul 7, 2012 · 3467 views
    This topic created in 5082 days ago, the information mentioned may be changed or developed.
    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
    5 replies    1970-01-01 08:00:00 +08:00
    fanzeyi
        1
    fanzeyi  
       Jul 7, 2012   ❤️ 1
    CONSTRAINT FOREIGN KEY (`groupid`, `groupname`)
    REFERENCES `group` (`id`, `groupname`)

    试试
    smoker
        2
    smoker  
    OP
       Jul 7, 2012
    沉的好快。。。
    那我说明下。。

    问题出在

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

    这段上,其中group是需要链接的表, id是PRIMARY KEY, groupname是UNIQUE KEY
    然后……然后就出错了。。。
    smoker
        3
    smoker  
    OP
       Jul 7, 2012
    居然成了。。。。谢谢!!!

    奇怪明明刚才自己加''了也不行。。。总之复制你这个好了。。
    qdvictory
        4
    qdvictory  
       Jul 7, 2012
    @smoker 那不是'号,而是`号
    fanzeyi
        5
    fanzeyi  
       Jul 7, 2012
    @smoker ` 号是 键盘左上角 ESC 下面 1 左边的那个按钮
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2944 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 06:55 · PVG 14:55 · LAX 23:55 · JFK 02:55
    ♥ Do have faith in what you're doing.