Sometimes when inserting data in a table with many columns it could be useful to know which columns must be specified if the insert-statement shouldn't fail.
I wrote this query to find out which columns are not nullable, identity, computed, timestamp and have no default value.
select *
from sys.columns
where object_id = object_id('<table>') and
is_nullable = 0 and
is_identity = 0 and
is_computed = 0 and
default_object_id = 0 and
type_name(system_type_id) <> 'timestamp'
Are there any other properties that should be included in this check?
Best Answer
The BOL documentation for the
INSERT
grammar has this to say aboutcolumn_list
It looks as though your query covers all these cases to me.