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'
