Is there a quick way to report database metadata in SQL Server 2005?

孤者浪人 提交于 2019-12-10 11:12:52

问题


Are there any system stored procs to report the stats and metadata of a database itself in SQL Server 2005?

What I need is a quick way to output a list of tables, the size of each table, the number of rows in each table and so on. Stored procs for individual tables and metadata would also be useful.

Advice appreciated.


回答1:


Yes, the data dictionary tables will let you do this. The main tables in the data dictionary are sys.objects, sys.columns, sys.indexes, sys.foreign_keys and sys.sql_modules. For an example of a variety of queries that use the system data dictionary to reverse-engineer a database to an SQL script, take a look at this stackoverflow posting.

Getting space usage is a bit more convoluted to do from the data dictionarybut sp_spaceused will do it for a single table. You can wrap this with sp_msforeachtable to iterate over a set of tables and get the report for all of the tables.




回答2:


Take a look at the system views, particularly information_schema.tables. These procs will also get a lot of the data you are looking for.

sp_helpdb dbname
sp_help objectname
sp_spaceused tablename



回答3:


Instead of querying the sysobjects etc... tables directly, you can use the INFORMATION_SCHEMA view.

In fact, the sysobjects was a table in SQL SErver2000, but in SQL 2005, it is implemented as a view, and it is kept to preserve backward compatability.



来源:https://stackoverflow.com/questions/454986/is-there-a-quick-way-to-report-database-metadata-in-sql-server-2005

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!