sql server 中獲取字段默認值SQL

獲取所有的默認值列表

select
object_name(c.id) as 表名
 ,c.name as 字段名
 ,t.name as 數據類型
 ,c.prec as 長度
 ,p.value as 字段說明
 ,m.text as 默認值
from syscolumns c
 inner join
 systypes t
 on c.xusertype=t.xusertype
 left join
 sysproperties p
 on c.id=p.id and c.colid = p.smallid
 left join
 syscomments m
 on c.cdefault=m.id

研究了很久 終於搞定了

獲取單個字段的默認值列表

select
object_name(c.id) as 表名
 ,c.name as 字段名
 ,t.name as 數據類型
 ,c.prec as 長度
 ,p.value as 字段說明
 ,m.text as 默認值
from syscolumns c
 inner join
 systypes t
 on c.xusertype=t.xusertype
 left join
 sysproperties p
 on c.id=p.id and c.colid = p.smallid
 left join
 syscomments m
 on c.cdefault=m.id
where objectproperty(c.id,'IsUserTable')=1
 and object_name(c.id) = 'T_good' and c.name = 'ishot' 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章