Jon Cage
Jon Cage

Reputation: 37448

Why does my (MySQL) INSERT operation fail?

I have a table with the following structure:

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

Why does the following query fail?

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

This the error message I get:

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

Upvotes: 0

Views: 111

Answers (3)

Shams
Shams

Reputation: 65

You can also use in this format

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');

Upvotes: 1

Amrita
Amrita

Reputation: 611

there is no need to insert the values that you have given as default like none,null etc.

Just insert the data using following query: insert into versions(project_id,name,sharing)values(10,'unplanned','none');

Sharing field I'm inserting because according to your table design it cannot be null.

Upvotes: 3

James Cronen
James Cronen

Reputation: 5763

If you don't specify a column list you need to add the keyword VALUES:

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

Upvotes: 4

Related Questions