2012-05-09 46 views
2

我試圖創建一個表像這樣:爲什麼我的SQL語句拋出語法錯誤?

CREATE TABLE Persons 
(
id int PRIMARY KEY AUTOINCREMENT, 
metalId varchar(255), 
colorId varchar(255) 
) 

,但它得到一個錯誤:

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 'AUTOINCREMENT, metalId varchar(255), colorId varchar(255))' at line 3

任何人都知道什麼是錯我的代碼?

回答

-1

嘗試

CREATE TABLE Persons 
(
id int PRIMARY KEY AUTO_INCREMENT, 
metalId varchar(255), 
colorId varchar(255) 
) 

Here is main source.

Syntax for MySQL

The following SQL statement defines the "P_Id" column to be an auto-increment primary key field in the "Persons" table:

CREATE TABLE Persons 
(
P_Id int NOT NULL AUTO_INCREMENT, 
LastName varchar(255) NOT NULL, 
FirstName varchar(255), 
Address varchar(255), 
City varchar(255), 
PRIMARY KEY (P_Id) 
) 

MySQL uses the AUTO_INCREMENT keyword to perform an auto-increment feature.

By default, the starting value for AUTO_INCREMENT is 1, and it will increment by 1 for each new record.

To let the AUTO_INCREMENT sequence start with another value, use the following SQL statement: ALTER TABLE Persons AUTO_INCREMENT=100