MySQL INSERT INTO syntax
11,049
RIGHT
is a mySQL reserved word. It will work only when wrapped in backticks.
When you're not using reserved words, it will work without the backticks, as well.
The second way will never work because quotes are used to quote strings, but never database, table or column identifiers.
Related videos on Youtube
Author by
Master345
Updated on September 15, 2022Comments
-
Master345 about 1 year
I have the following structure
user_id int(11) right int(11) group_id int(11) value tinyint(1)
And 3 queries
INSERT INTO user_rights (`user_id`,`right`,`group_id`,`value`) VALUES ( '42', '160', '1', '1' ); INSERT INTO user_rights ('user_id','right','group_id','value') VALUES ( '42', '160', '1', '1' ); INSERT INTO user_rights (user_id,right,group_id,value) VALUES ( '42', '160', '1', '1' );
Explain me WHYYYY only the first works????
I have all my life used the third one!
-
Master345 over 11 yearsthanks, but ... this is an stupidity, why not ' and ` ?? ... nevermind, thanks
-
Pekka over 11 years@Row no problem. There are good reasons for this distinction - one is for objects like column and table names, the other for strings. But I agree mySQL's error messages are a bit cryptic in this regard