查詢SQL Server資料庫所有表字段備註

2022-01-13 22:12:54 字數 1521 閱讀 6764

select 

表名 = case when a.colorder=1 then d.name else '' end,

表說明 = case when a.colorder=1 then isnull(f.value,'') else '' end,

字段序號 = a.colorder,

欄位名 = a.name,

字段說明 = isnull(g.[value],''),

型別 = b.name,

占用位元組數 = a.length,

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

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

主鍵 = case when exists(select 1 from sysobjects where xtype='pk' and parent_obj=a.id and name in (

select name from sysindexes where indid in( select indid from sysindexkeys where id = a.id and colid=a.colid))) then '√' else '' end,

小數字數 = isnull(columnproperty(a.id,a.name,'scale'),0),

允許空 = case when a.isnullable=1 then '√'else '' end,

預設值 = isnull(e.text,'')

from

syscolumns a

left join

systypes b

on a.xusertype=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.major_id and f.minor_id=0

--where d.name in ( 'tablename1','tablename2') --如果只查詢指定表,加上此紅色where條件,tablename是要查詢的表名;去除紅色where條件查詢說有的表資訊

order by a.id,a.colorder

SQL Server資料庫查詢

開啟我們的sql server資料庫,找到要查詢的資料庫表,右鍵單擊然後選擇新建查詢,select 選擇我們要查詢的表sys academe學院表 聯合 sys class.classname班級表的班級名稱和sys grade.gradename年級表的年級編號來查詢出資料。下面是查詢的 sele...

SQL Server 跨資料庫查詢

語句 select from 資料庫a.dbo.表a a,資料庫b.dbo.表b b where a.field b.field dbo 可以省略 如 select from 資料庫a.表a a,資料庫b.表b b where a.field b.field sqlserver資料庫 這句是對映乙個...

查詢SQL SERVER 資料庫版本

select substring cast serverproperty productversion as nvarchar 128 1,charindex cast serverproperty productversion as nvarchar 128 1 1 8 對應 sql server...