0

我有一个具有以下结构的表:

--------------
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

3 回答 3

4

如果您不指定列列表,则需要添加关键字VALUES

INSERT INTO versions VALUES (10, 'Unplanned', ' ', null, null, null, null, 'open', 'none');
于 2012-07-18T12:17:29.003 回答
3

无需插入您提供的默认值,例如 none、null 等。

只需使用以下查询插入数据: insert into versions(project_id,name,sharing)values(10,'unplanned','none');

我要插入共享字段,因为根据您的表格设计,它不能为空。

于 2012-07-18T12:35:37.840 回答
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');
于 2012-07-18T12:24:39.413 回答