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'
posted @ 2015-07-14 15:24  libingql  阅读(10457)  评论(0编辑  收藏  举报