This is a list of SQL queries for SQL Server Catalog Views / Data Dictionary handy for any SQL Server DBA.

  1. List of tables with number of rows and comments
  2. List of views with definition and comments
  3. Table columns details
  4. Foreign keys
  5. Views columns
  6. Tables by number of columns

 

1. List of tables with number of rows and comments

This query returns list of tables in a database sorted by schema and table name with comments and number of rows in each table.

 

2. List of views with definition and comments

This query returns list of database views with their definition SQL and a comment.

 

3. Table columns details

This query returns list of tables and their columns with details.

 

4. Foreign keys

This query returns list of tables and their foreign keys.

 

5. Views columns

This query returns list of views with their columns.

 

6. Tables by number of columns

This query returns list of tables sorted by the number of columns they contain.

 

Leave a Comment