Created
June 7, 2012 02:37
-
-
Save ichiroku11/2886211 to your computer and use it in GitHub Desktop.
テーブル名、カラム名からデフォルト制約名を取得するクエリ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare @table sysname = 'table_name'; | |
declare @column sysname = 'column_name'; | |
select | |
sys.default_constraints.name, * | |
from sys.tables | |
inner join sys.columns | |
on sys.tables.object_id = sys.columns.object_id | |
inner join sys.default_constraints | |
on sys.tables.object_id = sys.default_constraints.parent_object_id and | |
sys.columns.column_id = sys.default_constraints.parent_column_id | |
where | |
sys.tables.type = 'U' and | |
sys.tables.name = @table and | |
sys.columns.name = @column and | |
sys.default_constraints.type = 'D'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment