"OK, so the SQL spec says that you can't have an implicit column list unless you have ALL the columns in the values () part. I agree. "
hehehe... I told you so 😃
" Oooo - ok I'm getting confused between the two difference syntaxes"
Ok, here's a recap:
The INSERT statement syntax is basically:
INSERT INTO table <column-list> VALUES <value-list>;
The value list contains the data you want to put into the table, and the column-list specifies which column each of the values should go in to.
The column-list is optional, but if you leave it out, then SQL assumes that you want to insert data into every column in the table, so the values-list must contain one value for every column in the table.
To keep the 'bad' programmers happy, databases appear to also allow you to specify fewer values than there are columns. The data in the values is inserted into the columns from left to right and when all values are used, the remaining columns will be filled with their defaults (if any)
So if you have a table consisting of 'name | id' and you run a query:
INSERT INTO table VALUES ('charles');
then there is no value for 'id', and SQL uses the default value for the 'id' column.
The bad thing about this is that the order of the values must match the order of the columns. So if you had to add a column to the table:
'name | id | occupation'
Then the trick stops working because you have to give the values for the columns from left to right, and you can't skip the id column anymore:
INSERT INTO table VALUES ('charles', 'gardner');
will try to insert 'gardner' into the 'id' column.
To keep things working you can tell SQL to use the 'default' value for the ID column, by putting DEFAULT in the values list:
INSERT INTO table VALUES ('charles', DEFAULT, 'gardner');
And as you can see, now we're back to the original 'you must give a value for each column in the table' rule.