When writing an INSERT statement with a lot of columns, it would be nice to have the value next to the column name like in an UPDATE statement. Something like:
insert into myTable
set
[col1] = 'xxx',
[col2] = 'yyy',
[col3] = 42
etc...
Are there any tricks to mimic this?
I thought I was onto something with this:
insert into myTable
select
[col1] = 'xxx',
[col2] = 'yyy',
[col3] = 42
etc...
But the aliases aren’t actually being associated with the insert table’s columns and if someone added a new column to the table it could really screw things up. Anyone have any other ideas of how one could do this?
The closest you’ll get would be to specify the columns on the insert (this will protect you from your concern about a new column being added) and alias the values on the select (which gives you some degree of self-documenting code).