Xurion Posted May 9, 2008 Share Posted May 9, 2008 Hi all, I'm having a debate at my office with a friend who says you shouldn't use the following to input: INSERT INTO mytable SET column='value', columnb='value' I've always used this method (as I think it's easier to look at) but my friend says you should only use the following method to input: INSERT INTO mytable (column, columnb) VALUES ('value', 'value') Is this correct or is his personal opinion clouding his knowledge? Thanks in advance Xur~ Link to comment https://forums.phpfreaks.com/topic/104826-solved-difference-between-set-and-values/ Share on other sites More sharing options...
fenway Posted May 9, 2008 Share Posted May 9, 2008 The latter is more useful, because you can create multi-valued insert statements. The only reason the former exists is for compatibility and similiarty to the update syntax. Link to comment https://forums.phpfreaks.com/topic/104826-solved-difference-between-set-and-values/#findComment-536695 Share on other sites More sharing options...
neoform Posted May 9, 2008 Share Posted May 9, 2008 What do you mean by "create multi-valued insert statements"? Link to comment https://forums.phpfreaks.com/topic/104826-solved-difference-between-set-and-values/#findComment-536732 Share on other sites More sharing options...
Mr. Despair Posted May 9, 2008 Share Posted May 9, 2008 How about using just: "INSERT INTO mytable VALUES ('value', 'value')" A lot of times I just skip the listing of the column names because I'm lazy, but I guess I shouldn't? Link to comment https://forums.phpfreaks.com/topic/104826-solved-difference-between-set-and-values/#findComment-536846 Share on other sites More sharing options...
PFMaBiSmAd Posted May 9, 2008 Share Posted May 9, 2008 What do you mean by "create multi-valued insert statements"? From the mysql manual - INSERT statements that use VALUES syntax can insert multiple rows. To do this, include multiple lists of column values, each enclosed within parentheses and separated by commas. Example: INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9); Link to comment https://forums.phpfreaks.com/topic/104826-solved-difference-between-set-and-values/#findComment-536856 Share on other sites More sharing options...
neoform Posted May 9, 2008 Share Posted May 9, 2008 ah, k, I was confusing 'value' with field. Link to comment https://forums.phpfreaks.com/topic/104826-solved-difference-between-set-and-values/#findComment-536878 Share on other sites More sharing options...
fenway Posted May 9, 2008 Share Posted May 9, 2008 How about using just: "INSERT INTO mytable VALUES ('value', 'value')" A lot of times I just skip the listing of the column names because I'm lazy, but I guess I shouldn't? No, you should NEVER do that... good luck if you ever change the order of the fields or add a new one! That's the only reason I don't like this syntax :-( Link to comment https://forums.phpfreaks.com/topic/104826-solved-difference-between-set-and-values/#findComment-536926 Share on other sites More sharing options...
crtreedude Posted May 10, 2008 Share Posted May 10, 2008 How about using just: "INSERT INTO mytable VALUES ('value', 'value')" A lot of times I just skip the listing of the column names because I'm lazy, but I guess I shouldn't? Only if you wish to experience what your user name suggest, despair. Clean code will help you preserve what little sanity remains. Trust me on this. When a project gets really large, with lots of hands in it, locking everything down tight is the only way to not lose your mind. I remember restoring a SQL database once and the field orders actually changed. I would suggest that you shouldn't ever assume the order of fields. There is no guarantee. Link to comment https://forums.phpfreaks.com/topic/104826-solved-difference-between-set-and-values/#findComment-537863 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.