Jump to content

[SOLVED] Difference between SET and VALUES


Xurion

Recommended Posts

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~

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);

 

 

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 :-(

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. :lol: 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.  :o  I would suggest that you shouldn't ever assume the order of fields. There is no guarantee.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.