INSERT into table without specifying Column names

As long as you have the right number of columns in your INSERT statement, and as long as all the values except KEYBOARD are some numeric data type, and as long as you have suitable permissions, this should work.

INSERT INTO INVOICE VALUES( 1,1,'KEYBOARD',1,15,5,75);

SQL requires single quotes around text values.

But not using column names isn’t a good practice. It’s not unheard of for people to change the order of columns in a table. Changing the order of columns isn’t a good practice, either, but some people insist on doing it anyway.

If somebody does that, and swaps the 5th and 7th columns in your table, your INSERT statement will still succeed–both those columns are numeric–but the INSERT will screw up your data.

Leave a Comment