Collecting tables information using procedure sp_tables_info

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 You input is greatly appreciated.

Get the Free Newsletter!

Subscribe to Cloud Insider for top news, trends & analysis

Latest Articles