+44 (0) 845 260 0726

Pixl8

You are:

  • | Share

Checking tables on SQL Server

Alex Skinner   Posted: 15 February 2007

I was reviewing a SQL Server database application the other day which had 100s of tables many of which I was pretty sure were not being used with the absence of any documentation i needed a way of listing all the tables and then finding out whether or not they contained data.

The following query did the trick and works on SQL Server 2000 and 2005

select so.name as tablename,
Max(si.rows) as Rows
FROM sysobjects so,
sysindexes si
WHERE so.type='U'
AND
si.id=OBJECT_ID(so.name)
GROUP BY so.name
ORDER BY Rows DESC

Update: Very useful, I've already lost track of how many times i've used this.

  1. Bookmark & Share :
  2. Delicious
  3. Digg
  4. Facebook
  1. Comments (0)
  2. 632 Views