Jump to content

For the MS SQL nerds - List of tables in database matching a string with their counts


Casper

Recommended Posts

I didn't find anything with a quick Google search so I started digging around. Came up with this:

select 'Table Name'=convert(char(25),t.TABLE_NAME),

'Record Count'=max(i.rows)

from sysindexes i, INFORMATION_SCHEMA.TABLES t

where t.TABLE_NAME = object_name(i.id)

and t.TABLE_TYPE = 'BASE TABLE'

and t.TABLE_NAME like '%Product%'

or t.TABLE_NAME = object_name(i.id)

and t.TABLE_TYPE = 'BASE TABLE'

and t.TABLE_NAME like '%Employee%'

group by t.TABLE_NAME

It finds all of the tables in the database that contain Employee or Product and lists the table names and the counts. Works on 2005 and 2008. Not sure it'd work in 2000. Probably not. I figured I'd share in case anyone else could use this. Obviously Employee and Product weren't actually what we were searching for. LOL

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...