Create Table fails in sqlyog

2.4k Views Asked by At
CREATE TABLE inventory
(
   id INT IDENTITY(1,1) PRIMARY KEY,
   product VARCHAR(50) UNIQUE,
   quantity INT,
   price DECIMAL(18,2)
);

error is

Error Code : 1064
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 'IDENTITY(1,1) PRIMARY KEY,
   product VARCHAR(50) UNIQUE,
   quantity INT,
   pr' at line 3
2

There are 2 best solutions below

0
On
CREATE TABLE inventory
(
   id INT PRIMARY KEY,
   product VARCHAR(50) UNIQUE,
   quantity INT,
   price DECIMAL(18,2)
);

This worked. I removed IDENTITY. I do not see IDENTITY in the create table doc of MySQL.


EDIT1 (got that OP's wrong syntax exported from T-SQL)

Ahh I got it... you are taking the SQL from T-SQL? Perhaprs you need auto increment use this

CREATE TABLE inventory
(
   id INT AUTO_INCREMENT PRIMARY KEY,
   product VARCHAR(50) UNIQUE,
   quantity INT,
   price DECIMAL(18,2)
);
0
On

I think you want to use AUTO_INCREMENT. Try this:

CREATE TABLE inventory
(
   id INT AUTO_INCREMENT PRIMARY KEY,
   product VARCHAR(50) UNIQUE,
   quantity INT,
   price DECIMAL(18,2)
);