sql语句
CREATE TABLE orderitem (
iid CHAR(32) PRIMARY KEY,/主键/
count
INT,/数量/orderitem
subtotal DECIMAL(10,0),/小计/
oid CHAR(32),/所属订单/
bid CHAR(32),/订单项所指的商品/
FOREIGN KEY (oid) REFERENCES orders (oid),/建立主外键关系/
FOREIGN KEY (bid) REFERENCES book (bid)/建立主外键关系/
);
报错如下:
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 'subtotal DECIMAL(10,0),
oid CHAR(32),
bid CHAR(32),
FOREIGN KEY (oid) REFE' at line 4
数据库版本 mysql-5.5.60-winx64
不知道怎么回事,请大神赐教!
把前面多了个orderitems,去掉应该可以了
mysql> CREATE TABLE orderitem (
-> iid CHAR(32) PRIMARY KEY,/主键/
-> COUNT INT,/数量/
-> subtotal DECIMAL(10,0),/小计/
-> oid CHAR(32),/所属订单/
-> bid CHAR(32),/订单项所指的商品/
-> FOREIGN KEY (oid) REFERENCES orders (oid),/建立主外键关系/
-> FOREIGN KEY (bid) REFERENCES book (bid)/建立主外键关系/
-> );
Query OK, 0 rows affected (0.16 sec)
varchar?
你后面的中文应该是注释吧?请用下面的语法:
CREATE TABLE orderitem (
iid CHAR(32) PRIMARY KEY COMMENT '主键',
count INT COMMENT '数量',
subtotal DECIMAL(10,0) COMMENT '小计',
oid CHAR(32) COMMENT '所属订单',
bid CHAR(32) COMMENT '订单项所指的商品',
FOREIGN KEY (oid) REFERENCES orders (oid) COMMENT '建立主外键关系',
FOREIGN KEY (bid) REFERENCES book (bid) COMMENT '建立主外键关系'
);
直接复制你修改的
mysql> CREATE TABLE orderitem (
-> iid CHAR(32) PRIMARY KEY COMMENT '主键',
-> count INT COMMENT '数量',
-> subtotal DECIMAL(10,0) COMMENT '小计',
-> oid CHAR(32) COMMENT '所属订单',
-> bid CHAR(32) COMMENT '订单项所指的商品',
-> FOREIGN KEY (oid) REFERENCES orders (oid) COMMENT '建立主外键关系',
-> FOREIGN KEY (bid) REFERENCES book (bid) COMMENT '建立主外键关系'
-> );
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 'COMMENT '建立主外键关系',
FOREIGN KEY (bid) REFERENCES book (bid) COMMENT' at line 7
mysql>
应该和注释没关系,这个项目其他几个表都有类似注释都可以执行。
先把所以中午删除掉执行下试试,如果行,再添加上