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

错误是

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
4

2 回答 2

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

这行得通。我删除了IDENTITY. 我在 MySQL 的创建表文档中没有看到IDENTITY


EDIT1(从 T-SQL 导出了 OP 的错误语法)

啊,我明白了...您是从 T-SQL 获取 SQL 吗?也许你需要自动增量使用这个

CREATE TABLE inventory
(
   id INT AUTO_INCREMENT PRIMARY KEY,
   product VARCHAR(50) UNIQUE,
   quantity INT,
   price DECIMAL(18,2)
);
于 2012-08-09T10:13:52.603 回答
0

我想你想用AUTO_INCREMENT. 尝试这个:

CREATE TABLE inventory
(
   id INT AUTO_INCREMENT PRIMARY KEY,
   product VARCHAR(50) UNIQUE,
   quantity INT,
   price DECIMAL(18,2)
);
于 2012-08-09T10:19:36.453 回答