INSERT Query & Column Names

Hello,

Should i specify the column names in the INSERT QUERY?
what are the Advantages and Disadvantage in doing that?

I don’t know of any db insert query where you CAN’T / DON’T specify the column names.

That doesn’t mean they don’t exist… just that I’ve never run across one.

But, how else can you make sure that the data is being put into the corresponding column?

INSERT into TableA(col1, col2, col3)
VALUES (val1, val2, val3)

:slight_smile:

to answer your question, yes, you can do it –

INSERT INTO tableA VALUES (val1,val2,val3)
this method requires that you provide a value for every column in the table

i hasten to add that it is better practice to specify the columns, but you don’t actually have to

1 Like

I did not realise you could actually do an insert that way… is that all db? Or just a specific flavour?

i’m pretty sure it’s standard sql

you can check which standard (92, 99, 2003) by submitting it to the Mimer SQL Validator

It is a standard although if my memory serves me well (and if not, @r937 will correct me) one of the disadvantages of using this particular way is that you have to follow the order of the columns as they’re in the table.

So if you don’t want to follow a particular order and you want to make sure that value A is inserted for column B, this method may not be the best for you

Thank you guys, thank you. so now i understood why it is a best practice to put column names in insert query.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.