Friday, June 25, 2010

SQL SERVER – How To Find the Number Of Records in a Table

There are multiple methods to find out the number of records in a table.

Let us first consider a table Organization.

Select  OrgId,Acctnum,CompId,OrgName,Phone              From  Organization

Output:

image

As shown in the above output, the Organization table Contains 5 records.

Now, To find out the Number of records in the table Organization, we can follow the below methods.

1. Using Count(*)

Example :                                                                          Select  Count(*) RecordCount  From  Organization

Output:

image

2. Using the System Stored Procedure                           

Example :                                                                              Exec SP_SpaceUsed  'Organization'

Output:

image

3. Using System Views                                               

Example :                                                                                     Select  Max(Rows) RecordCount                                 From SysObjects So, SysIndexes Si
where so.type='U' and si.id=object_id('Organization')

Output:

image

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.