-- 查詢非系統數據庫
Select name FROM Master.. SysDatabases where dbid>4-- 選擇water數據庫下的所有表
use [water] SELECT name FROM sysobjects WHERE xtype = 'U' Or xtype = 'S'-- 選擇water數據庫下的所有用戶表
use [water] SELECT name FROM sysobjects WHERE xtype = 'U' AND OBJECTPROPERTY (id, 'IsMSShipped') = 0-- 查詢water數據庫下的admin表的字段名,長度,類型,字段說明
use [water] SELECT a.[name] as '字段名',a.length '長度',c.[name] '類型',e.value as '字段說明' FROM syscolumns a
left join systypes b on a.xusertype=b.xusertype
left join systypes c on a.xtype = c.xusertype
inner join sysobjects d on a.id=d.id and d.xtype='U'
left join sys.extended_properties e on a.id = e.major_id and a.colid = e.minor_id and e.name='MS_Description'
where d.name='admin'
sys.extended_properties系統內置視圖用于存儲字段說明。
查詢某張表的字段信息的話還可用如下方法:
select * from information_schema.columns where table_name ='colocal'