How do I find a default constraint using INFORMATION_SCHEMA?

前端 未结 14 819
猫巷女王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:28

    Probably because on some of the other SQL DBMSs the "default constraint" is not really a constraint, you'll not find its name in "INFORMATION_SCHEMA.TABLE_CONSTRAINTS", so your best bet is "INFORMATION_SCHEMA.COLUMNS" as others have mentioned already.

    (SQLServer-ignoramus here)

    The only a reason I can think of when you have to know the "default constraint"'s name is if SQLServer doesn't support "ALTER TABLE xxx ALTER COLUMN yyy SET DEFAULT..." command. But then you are already in a non-standard zone and you have to use the product-specific ways to get what you need.

提交回复
热议问题