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
SQL Server 的所有表查詢和注釋說明查詢
學習sql server時,用到了2條特殊查詢語句,特意來記錄一下,一是查詢資料庫中所有的資料庫表,二是查詢資料庫表中的說明字段 1 查詢資料庫中所有的資料庫表 select from sysobjects where xtype u and name sysdiagrams 2 查詢資料庫表中的說...
sqlserver 查詢所有表及記錄行數
查詢所有表名 select name from sysobjects where xtype u select from sys.tables 查詢所有表名及對應架構 select t.name as tablename,s.name as schema from sys.tables as t,s...
所有的表sqlserver
select o.name as tablename,user name o.uid as owner,isnull ptb.value,n as tabledescription,c.colid as fieldid,c.name as fieldname,quotename t.name cas...