Mysql 我的SQL语法有什么问题
将您的代码与MySQL手册中的代码进行比较:Mysql 我的SQL语法有什么问题,mysql,Mysql,将您的代码与MySQL手册中的代码进行比较: create table const_category ( cat_id int(8) not null auto_increment primary key, cat_label varchar(150) ) ENGINE=InnoDB; create table const_subcategory ( subcat_id int(11) not null auto_increment primary key,
create table const_category (
cat_id int(8) not null auto_increment primary key,
cat_label varchar(150)
) ENGINE=InnoDB;
create table const_subcategory (
subcat_id int(11) not null auto_increment primary key,
subcat_label varchar(150),
cat_id int(9) not null,
FOREIGN KEY cat_id REFERENCES const_category(cat_id)
)ENGINE=InnoDB;
在外键声明中,列名周围没有括号
参考:
将约束名称放在括号中,如
外键(cat\u id)
在这里看小提琴你会得到什么错误?你是收到错误信息还是什么?你想做什么?在没有指令的情况下破译您的代码不是我们的工作。来自SQL FIDLE的错误消息:
您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以了解在第1行的“REFERENCES const_category(cat_id))ENGINE=InnoDB”附近使用的正确语法:
CREATE TABLE child (
id INT,
parent_id INT,
INDEX par_ind (parent_id),
FOREIGN KEY (parent_id)
REFERENCES parent(id)
ON DELETE CASCADE
) ENGINE=INNODB;
create table const_subcategory (
subcat_id int(11) not null auto_increment primary key,
subcat_label varchar(150),
cat_id int(9) not null,
FOREIGN KEY (cat_id) REFERENCES const_category(cat_id)
);