2013-01-09 100 views

回答

1

查詢

select COLUMN_DEFAULT 
from INFORMATION_SCHEMA.COLUMNS 
where TABLE_NAME = @tableName 
and COLUMN_NAME = @columnName 

將返回一列指定的默認值(null如果沒有默認定義)


更新:

下面的查詢也將檢索約束的名稱:

select 
    dc.name, 
    dc.definition 
from sys.default_constraints dc 
join sys.objects o 
    on o.object_id = dc.parent_object_id 
join sys.columns c 
    on o.object_id = c.object_id 
    and c.column_id = dc.parent_column_id 
where o.name = @tableName 
and c.name = @columnName 

如果沒有行返回,那麼在該列上沒有定義默認約束。