SQL Server tables in one swoop!

This is how to list all tables in a SQL Server Database with one statement, or two.

--Tables by Rows Descending Order
SELECT sysobjects.Name,
       sysindexes.Rows
FROM   sysobjects
INNER JOIN sysindexes ON sysobjects.id = sysindexes.id
WHERE type = 'U' AND sysindexes.IndId < 2
ORDER BY sysindexes.Rows DESC

--Tables by Table Names
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

Comments are closed