showkey
showkey

Reputation: 298

ERROR 1064 (42000): errror near ' PRIMARY KEY

My sql script is as below:

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`);

source it in mysql commad line,an error info occurs.

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

How to fix my sql script?

Upvotes: 0

Views: 150

Answers (1)

fifonik
fifonik

Reputation: 1606

You'll need to add brackets as per manual:

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

Upvotes: 1

Related Questions