WeSee WeSee - 3 years ago 204
SQL Question

MySQL Error Message "#1064 - You have an error..."

I'm using MySQL 5.6.33.

My table definition is:

CREATE TABLE test (
id int(11) NOT NULL AUTO_INCREMENT,
a1 varchar(255) NOT NULL,
a2 varchar(255) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;


Executing an
INSERT
statement

INSERT INTO test ('a1', 'a2') VALUES ('hello', 'world');


throws the ugly error message

#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 ''a1', 'a2') VALUES('hello', 'world')' at line 1


I tried modifying the AUTO_INCREMENT, incluing the primary key as in

INSERT INTO test ('id', 'a1', 'a2') VALUES (NULL,'hello', 'world');


But nothing works. Allways the same error.

I could not find any answer on SO that could resolve this. How to proceed?

Answer Source

Your are not suppose to use ' single-quote in with column name

INSERT INTO test ('a1', 'a2') VALUES ('hello', 'world');

instead

INSERT INTO test (a1, a2) VALUES ('hello', 'world');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download