SqlServer 查询系统数据库列表、表和表字段等对象

1 查询系统数据库列表

select * from master.sys.databases

 2.1 查询指定数据库有哪些表

-- 查询数据库'MyMVC'有哪些表
SELECT * 
FROM MyMVC.INFORMATION_SCHEMA.TABLES

 

 

 2.2 查询表

-- 查询数据库 'Test' 表、视图和存储过程等相关信息
select * from Test.sys.sysobjects where type='U' -- 用户表
select * from Test.sys.sysobjects where type='V' -- 视图
select * from Test.sys.sysobjects where type='P' -- 存储过程
select * from Test.sys.sysobjects where type='FN' -- 标量值函数
select * from Test.sys.sysobjects where type='IF' -- 内嵌表值函数
select * from Test.sys.sysobjects where type='TF' -- 表值函数

3 查询表的字段信息

-- 查询表 'person' 的所有列相关信息
select c.name as [col_name],t.name as [type_name],c.max_length,c.is_nullable
from test.sys.columns as c
inner join test.sys.types as t on c.user_type_id = t.user_type_id
where c.[object_id] = object_id('person')

查询结果:

posted @ 2020-09-06 12:00  温故纳新  阅读(2360)  评论(0编辑  收藏  举报