The Little Guy Posted March 19, 2011 Share Posted March 19, 2011 I know of two ways write an sql insert, insert into table a (1,2,3) values (1,2,3); or insert into table a set 1=1, 2=2, 3=3; is one of the way deprecated, and/or is one better than the other? Quote Link to comment https://forums.phpfreaks.com/topic/231124-which-insert-is-better/ Share on other sites More sharing options...
sunfighter Posted March 21, 2011 Share Posted March 21, 2011 When you don't specify the column names where the data will be inserted you should be inserting into all the columns: INSERT INTO table_name VALUES (value1, value2, value3,...) If your going to specify the column names use this form: INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...) The last form is good when your not inserting into all columns, but also works as a replacement for the first form. Quote Link to comment https://forums.phpfreaks.com/topic/231124-which-insert-is-better/#findComment-1190144 Share on other sites More sharing options...
gizmola Posted March 21, 2011 Share Posted March 21, 2011 The first form is the most standard across different RDBMS. Quote Link to comment https://forums.phpfreaks.com/topic/231124-which-insert-is-better/#findComment-1190145 Share on other sites More sharing options...
The Little Guy Posted March 21, 2011 Author Share Posted March 21, 2011 okay. when was the second method introduced into MySQL? Quote Link to comment https://forums.phpfreaks.com/topic/231124-which-insert-is-better/#findComment-1190305 Share on other sites More sharing options...
fenway Posted March 29, 2011 Share Posted March 29, 2011 It was probably a backwards-compatibility issue... but the first one is preferred for multi-valued options. Quote Link to comment https://forums.phpfreaks.com/topic/231124-which-insert-is-better/#findComment-1193915 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.