Skip to content

Instantly share code, notes, and snippets.

@ichiroku11
Created June 7, 2012 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ichiroku11/2886211 to your computer and use it in GitHub Desktop.
Save ichiroku11/2886211 to your computer and use it in GitHub Desktop.
テーブル名、カラム名からデフォルト制約名を取得するクエリ
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