Sql Server系列:SQL語句查詢資料庫中表、檢視、儲存過程等組成

libingql發表於2015-07-14

1. 檢視使用者表

select name from sys.tables
select name from sys.objects where type='U'
select name from sysobjects where xtype='U'

  其中type或xtype值:U = 使用者表 S = 系統表 V = 檢視 FN = 標量函式 TF = 表函式 P = 儲存過程  TR = 觸發器

  D = 預設值或 DEFAULT 約束 PK = PRIMARY KEY 約束 F = FOREIGN KEY 約束 UQ = UNIQUE 約束

SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES

2. 檢視檢視

SELECT * FROM INFORMATION_SCHEMA.VIEWS

3. 檢視錶/檢視欄位

SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Product' 
-- 檢視VProduct
SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'VProduct' 
select name from syscolumns where id = object_id('Product')
SELECT COLUMN_NAME,DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Product'

相關文章