Click here to Skip to main content
15,881,870 members
Articles / Database Development
Alternative
Tip/Trick

Record Count of Tables in SQL Server

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
16 Aug 2011CPOL 7K   1   1
Sometimes it is necessary to have the schema name included as well. I concatenate with the table name for my convenience, but it is not vital to do so.SELECT sys.sysindexes.rows, sys.schemas.name + '.' + sys.objects.nameFROM sys.objectsINNER JOIN sys.schemasON ...

Sometimes it is necessary to have the schema name included as well. I concatenate with the table name for my convenience, but it is not vital to do so.


SQL
SELECT        sys.sysindexes.rows, sys.schemas.name + '.' + sys.objects.name
FROM          sys.objects
INNER JOIN    sys.schemas
ON            sys.objects.schema_id = sys.schemas.schema_id
INNER JOIN    sys.sysindexes
ON            sys.objects.object_id = sys.sysindexes.id
WHERE         sys.objects.type = 'u'
AND           sys.objects.name <> 'dtproperties'
AND           sys.objects.name <> 'sysdiagrams'
AND           sys.sysindexes.indid < 2

Also get rid of a couple of tables which we don't need to see in the count.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United Kingdom United Kingdom
I have been developing applications for almost 30 years - started with early versions of Basic on the Sinclair ZX80, moving up via UK101 and Amstrad to PC. Played with Assembly as well. First big application was for a complete test set, which was written using QuickBasic (all I had available to me). Moved on to a bit of C and C++ (never really got to grips with them) and then 11 years ago, got into Visual Basic/SQL Server and HTML. Moved onto .NET and then in the last few years changed across to C# when the job market indicated that it would be better.
Have now developed quite a few ASP.NET Applications, and along the way have played with WPF, Silverlight and am currently working on an MVC based application.

Comments and Discussions

 
GeneralReason for my vote of 5 I was just about to write up this al... Pin
John B Oliver13-Sep-11 12:02
John B Oliver13-Sep-11 12:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.