Sql Server系列:SQL語句查詢數據庫中表、視圖、存儲過程等組成


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'


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM