標籤:
一、系統資料庫表(master)
select * from sysaltfiles 主要資料庫,儲存資料庫的檔案
select * from syscharsets 主要資料庫字元集與排序次序
select * from sysconfigures 主要資料庫,配置選項
select * from syscurconfigs 主要資料庫當前配置選項
select * from sysdatabases 主要資料庫伺服器中的資料庫
select * from syslanguages 主要資料庫語言
select * from syslogins 主要資料庫,登陸帳號資訊
select * from sysoledbusers 主要資料庫,連結的伺服器登陸資訊
select * from sysprocesses 主要資料庫進程
select * from sysremotelogins 主要資料庫,遠程登入帳號
select * from syscolumns 每個資料庫列
select * from sysconstrains 每個資料庫,限制
select * from sysfilegroups 每個資料庫,檔案組
select * from sysfiles 每個資料庫,檔案
select * from sysforeignkeys 每個資料庫,外部關鍵字
select * from sysindexs 每個資料庫,索引
select * from sysmenbers 每個資料庫角色成員
select * from sysobjects 每個資料庫所有資料庫物件
select * from syspermissions 每個資料庫,許可權
select * from systypes 每個資料庫,使用者定義資料類型
select * from sysusers 每個資料庫,使用者
二、根據系統資料庫查詢到一些特別情況下需要的結果
1.擷取某個表中的所有欄位的名稱和類型
select a.name as fieldname,b.type_desc,b.type,t.name as typename from sys.columns a
left join sys.objects b on a.object_id=b.object_id left join sys.types t on a.system_type_id=t.system_type_id
where b.type = ‘U‘ and charindex(‘UDT‘,t.name,0)<=0 and charindex(‘sys‘,t.name,0)<=0 and b.name =‘cf_user‘
其中b.type為類型,U表示是使用者表,V表示是視圖
2.查詢某個表的欄位列和說明
SELECT t.[name] AS 表名, c.[name] AS 欄位名, cast(ep.[value] as nvarchar(200)) AS [欄位說明]
FROM sys.tables AS t INNER JOIN sys.columns AS c ON t.object_id = c.object_id
LEFT JOIN sys.extended_properties AS ep ON ep.major_id = c.object_id
AND ep.minor_id = c.column_id WHERE ep.class =1 AND t.name=‘tbgExpended‘
3.查詢某個欄位在哪些表中存在
Select a.name as Columns, b.name as TableName from syscolumns a left
join sysobjects b on a.id = b.id Where b.type = ‘U‘ and a.name =‘ITEM_CATEGORY‘ order by b.name
sql server系統資料庫