user1082764
user1082764

Reputation: 2015

mysql insert auto increment and date

mytable
+-----------+----------+------+-----+---------+----------------+
| Field     | Type     | Null | Key | Default | Extra          |
+-----------+----------+------+-----+---------+----------------+
| id        | int(255) | NO   | PRI | NULL    | auto_increment |
| date      | date     | NO   |     | NULL    |                |
| answer_id | int(255) | NO   | MUL | NULL    |                |
| count     | int(255) | YES  |     | NULL    |                |
+-----------+----------+------+-----+---------+----------------+

SQL:

INSERT INTO mytable ('date', 'answer_id', 'count')
VALUES ('2013-12-05', '4', '1'); 

gives me ERROR 1064

Upvotes: 1

Views: 345

Answers (3)

NULL
NULL

Reputation: 313

ERROR 1064 stands for syntax error.

Your column names should be wrapped with backtick on both side.
So change your SQL Query to:

INSERT INTO mytable ( `date`      , `answer_id`, `count` )
VALUES              ( '2013-12-05',          4 ,      1  ); 

Upvotes: 1

Dai
Dai

Reputation: 155055

Error 1064 is a syntax error, in this case your column names shouldn't be in quotes (but they can be in backticks) and your integer values shouldn't be in quotes either.

Your statement should look like this:

INSERT INTO mytable ( `date`      , `answer_id`, `count` )
VALUES              ( '2013-12-05',          4 ,      1  ); 

Upvotes: 3

zerkms
zerkms

Reputation: 254906

Columns shouldn't be enclosed in single quotes. Single quotes are used to delimit a string literal.

In your case you just omit any quotes around all columns.

If a column name matches a mysql keyword it needs to be wrapped with a backtick ` on either side.

Upvotes: 6

Related Questions