sql server系統資料庫

來源:互聯網
上載者:User

標籤:

一、系統資料庫表(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系統資料庫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.