Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» Sitemap
Free Newsletters:
DatabaseDaily  
News Via RSS Feed


follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2
 

Featured Database Articles

MS SQL

Posted Dec 11, 2000

Collecting tables information using procedure sp_tables_info

By Maxim Smirnov

Stored procedure sp_tables_info is designed to provide information required for tables' optimization process. For the database given as a parameter (by default current connected database will be chosen) it will go through each user table and will collect indexes and constrains information.

Proper indexes and constrains implementation strategy is essential for database performance and must be selected very carefully. Constrains support referential integrity between tables. Indexes are used for faster data access.

Procedure will display the following information:

  • Table name
  • Table system ID
  • Existence of the primary key constrains (values 0 or 1) (PKC)
  • Number of unique constrains (UNC)
  • Number of foreign key constrains (FKC)
  • Existence of the clustered indexes (values 0 or 1) (IND_CL)
  • Number of non-clustered indexes (IND_NC)
  • Special flag (*) indicating that clustered index is not defined
  • Number of records in the table (approximate) (ROWCNT)
Most of the tables should have a clustered index, especially if the number of records is large. Generally speaking, each table should have an index, and if there is one, is should be clustered. That is why the flag is implemented to bring your attention to the tables without clustered indexes.

I suggest creating this procedure in master database. This way stored procedure can be called from any connection by any user defined in master database.

If you have any questions or would like to suggest how to improve this procedure feel free to contact me at feedback@databasejournal.com. You input is greatly appreciated.



MS SQL Archives

Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 




Latest Forum Threads
MS SQL Forum
Topic By Replies Updated
SQL 2005: SSIS: Error using SQL Server credentials poverty 3 August 17th, 07:43 AM
Need help changing table contents nkawtg 1 August 17th, 03:02 AM
SQL Server Memory confifuration bhosalenarayan 2 August 14th, 05:33 AM
SQL Server Primary Key and a Unique Key katty.jonh 2 July 25th, 10:36 AM