MSSQL查询所有数据库表,指定数据库的字段、索引

--查询所有数据库
USE master
go
select [name] from [sysdatabases] order by [name]

--查询其中一个数据库test,就可以得到这个数据库中的所有的表名了,语句如下:
USE test
go
select [id], [name] from [sysobjects] where [type] = 'u' order by [name]

--查出v_lyb这个表中所有的字段
select [name] from [syscolumns] where [id] = 21575115 order by [colid]

--得到该表中的记录条数前提这个表中要建立索引

select [o].[id], [o].[name], [i].[rows] from [sysindexes] [i], [sysobjects] [o] where [i].[first]>0 and [o].[id]=[i].[id] and [o].[type]='u' and [o].[id]=21575115

 
原文地址:https://www.cnblogs.com/wangyuelang0526/p/2574619.html