How do I find a default constraint using INFORMATION_SCHEMA?

前端 未结 14 828
猫巷女王i
猫巷女王i 2020-12-04 13:40

I\'m trying to test if a given default constraint exists. I don\'t want to use the sysobjects table, but the more standard INFORMATION_SCHEMA.

I\'ve used this to che

14条回答
  •  孤街浪徒
    2020-12-04 14:26

    You can use the following to narrow the results even more by specifying the Table Name and Column Name that the Default Constraint correlates to:

    select * from sysobjects o 
    inner join syscolumns c
    on o.id = c.cdefault
    inner join sysobjects t
    on c.id = t.id
    where o.xtype = 'D'
    and c.name = 'Column_Name'
    and t.name = 'Table_Name'
    

提交回复
热议问题