Wednesday, 7 June 2017

sql - mysql syntax error



I wrote this simple query statement:



INSERT INTO merchants 
('firstName','lastName')
VALUES
('Bob','Smith')



Sounds very simple but I keep getting this error:



`#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 ''firstName','lastName' )
VALUES
('Bob','Smith' )' at line 2


Answer



You need to remove the quotes from around firstName and lastName:




INSERT INTO merchants 
(firstName,lastName)
VALUES
('Bob','Smith')


Column names are identifiers, and as such are not quoted.



Edit: Column names can be quoted using backticks (`), but this is only necessary if you have column names that contain special characters or column names that match MySQL keywords.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...