2012-07-18 74 views
0

我有以下結構的表:爲什麼我的(MySQL)INSERT操作失敗?

-------------- 
SHOW COLUMNS FROM versions 
-------------- 

+-----------------+--------------+------+-----+---------+----------------+ 
| Field   | Type   | Null | Key | Default | Extra   | 
+-----------------+--------------+------+-----+---------+----------------+ 
| id    | int(11)  | NO | PRI | NULL | auto_increment | 
| project_id  | int(11)  | NO | MUL | 0  |    | 
| name   | varchar(255) | NO |  |   |    | 
| description  | varchar(255) | YES |  |   |    | 
| effective_date | date   | YES |  | NULL |    | 
| created_on  | datetime  | YES |  | NULL |    | 
| updated_on  | datetime  | YES |  | NULL |    | 
| wiki_page_title | varchar(255) | YES |  | NULL |    | 
| status   | varchar(255) | YES |  | open |    | 
| sharing   | varchar(255) | NO | MUL | none |    | 
+-----------------+--------------+------+-----+---------+----------------+ 

爲什麼下面的查詢會失敗?

INSERT INTO versions (10, 'Unplanned', ' ', null, null, null, null, 'open', 'none'); 

此錯誤消息我得到:

ERROR 1064 (42000): 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 '10, 'Unplanned', ' ', null, null, null, null, 'open', 'none')' at line 1 

回答

4

如果不指定你需要添加關鍵字VALUES列的列表:

INSERT INTO versions VALUES (10, 'Unplanned', ' ', null, null, null, null, 'open', 'none'); 
1

您也可以使用這種格式

INSERT INTO versions(id,project_id,name,description,effective_date,created_on,updated_on,wiki_page_title,status,sharing) VALUES (10, 'Unplanned', ' ', null, null, null, null, 'open', 'none'); 
3

沒有必要插入你給默認像沒有價值,空等

只需插入使用下面的查詢數據: INSERT INTO版本(PROJECT_ID,名稱,共享)的值(10, '無計劃', '無');

我插入的共享字段,因爲根據您的表格設計它不能爲空。