mysql外键创建表

时间:2012-05-30 23:18:37

标签: mysql foreign-keys

String query = "CREATE TABLE IF NOT EXISTS platforms ( " +
                   "id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, " +
                   "sites_id INTEGER UNSIGNED NOT NULL, " +
                   "baseline BLOB NULL, " +
                   "platform BLOB NULL, " +
                   "siteinfo BLOB NULL, " +
                   "databases BLOB NULL, " +
                   "PRIMARY KEY(id), " +
                   "INDEX (sites_id), " +
                   "FOREIGN KEY (sites_id) " +
                     "REFERENCES sites (id) " +
                        "ON DELETE NO ACTION " +
                        "ON UPDATE NO ACTION " +
                   ")ENGINE=InnoDB;";

这是我正在尝试创建的MySQL数据库的SQL查询。但是,我不知道为什么,我收到以下错误:

  

“您的SQL语法有错误;请查看与您的MySQL服务器版本对应的手册,以便在'数据库BLOB NULL,PRIMARY KEY(id),INDEX(sites_id),FOREIGN KEY(sites_id)附近使用正确的语法)R'在第1行“

有人可以指出问题是什么吗?

1 个答案:

答案 0 :(得分:3)

DATABASESreserved word。使用反引号`字符引用它:

`databases` BLOB NULL