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~

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.