错误1064(42000):“ PRIMARY KEY”附近存在错误

时间:2019-02-27 02:58:29

标签: mysql primary-key

我的sql脚本如下:

CREATE database `stock`;
USE  `stock`;
CREATE TABLE `stock_all` (
      `state_dt` varchar(45),
      `stock_code` varchar(45),
      `open` decimal(20,2),
      UNIQUE INDEX `stock_code`,
      PRIMARY KEY `state_dt`);

在mysql逗号行中提供它,发生错误信息。

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '
      PRIMARY KEY `state_dt`)' at line 5

如何修复我的sql脚本?

1 个答案:

答案 0 :(得分:1)

您需要按照手册添加括号:

CREATE TABLE `stock_all` (
      `state_dt` varchar(45),
      `stock_code` varchar(45),
      `open` decimal(20,2),
      UNIQUE INDEX (`stock_code`),
      PRIMARY KEY (`state_dt`)
);