$0I see a flaw with the example query. When joining sys.default_constraints to sys.columns, the example only joins ON parent_column_id = column_id but this causes an issue when there are column_id(s) in sys.columns that overlap the column_ids in the sys.default_constraints values for the given table. This can be resolved by joining also on d.parent_object_id = c.[object_id]:$0
$0
$0SELECT d.definition $0
$0FROM sys.default_constraints AS d$0
$0INNER JOIN sys.columns AS c$0
$0ON d.parent_c
↧