SqlServer查詢表的字段和注釋

2022-01-22 13:05:52 字數 1310 閱讀 2555

select (case when a.colorder=1 then d.name else null end) 表名,

a.colorder 字段序號,a.name 欄位名,

(case when columnproperty( a.id,a.name,'isidentity')=1 then '√'else '' end) 標識,

(case when (select count(*) from sysobjects

where (name in (select name from sysindexes

where (id = a.id) and (indid in

(select indid from sysindexkeys

where (id = a.id) and (colid in

(select colid from syscolumns where (id = a.id) and (name = a.name)))))))

and (xtype = 'pk'))>0 then '√' else '' end) 主鍵,b.name 型別,a.length 占用位元組數,

columnproperty(a.id,a.name,'precision') as 長度,

isnull(columnproperty(a.id,a.name,'scale'),0) as 小數字數,(case when a.isnullable=1 then '√'else '' end) 允許空,

isnull(e.text,'') 預設值,isnull(g.[value], ' ') as [說明]

from syscolumns a

left join systypes b on a.xtype=b.xusertype

inner join sysobjects d on a.id=d.id and d.xtype='u' and d.name<>'dtproperties'

left join syscomments e on a.cdefault=e.id

left join sys.extended_properties g on a.id=g.major_id and a.colid=g.minor_id

left join sys.extended_properties f on d.id=f.class and f.minor_id=0

where b.name is not null

--where d.name='要查詢的表' --如果只查詢指定表,加上此條件

order by a.id,a.colorder

SqlServer欄位說明查詢(表基本資訊查詢)

快速檢視表結構 比較全面的 select case when col.colorder 1then obj.name else end as表名,col.colorder as序號 col.name as列名 isnull ep.value as 列說明 t.name as資料型別 col.leng...

sql server 查詢欄位上的約束

1.當欄位沒有預設值或者約束的時候可以使用 alter table table name drop column column name 來刪除。當有預設值的時候應該先刪除預設值,然後再刪除此列,不然會報錯。具體方法如下 select b.name from sysobjects b join sy...

SQL Server查詢某個字段存在哪些表中

一 查詢sql server中所有的表 sql語句 select from sys.tables name列表示所有的表名。二 查詢sql server中所有的列 sql語句 select from sys.columns name列表示所有的欄位名稱。兩張表根據object id進行關聯。語法 s...