Everything about your SQL Server databases is stored in its system tables (sysobjects, sysindexes) and SQL Server maintains at least one row in sysindexes.
The sysobjects.Name column lists the names of the objects while sysobjects.type identifies the type of object, using the following codes:
- C: Check constraint
- D: Default constraint
- F: Foreign Key constraint
- L: Log
- P: Stored procedure
- PK: Primary Key constraint
- RF: Replication Filter stored procedure
- S: System table
- TR: Trigger
- U: User table
- UQ: Unique constraint
- V: View
- X: Extended stored procedure
The following SQL statement will list all tables within a database and count the number of records within the database.
SELECT sysobjects.Name , sysindexes.Rows FROM sysobjects INNER JOIN sysindexes ON sysobjects.id = sysindexes.id WHERE type = 'U' AND sysindexes.IndId < 2 ORDER BY sysobjects.Name
References & Sources
- Getting a SQL Server RowCount Without doing a Table Scan (www.mssqltips.com)