Counting number of rows in Ms sql server table? [Resolved]

Posted by Sksamantaray under Sql Server on 3/25/2012 | Points: 10 | Views : 5191 | Status : [Member] | Replies : 5
What are the possible ways to count number of rows of a specified table?

Thanks,
Sanjay



Responses

Posted by: Skraghava on: 3/25/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
SELECT COUNT(*) FROM TableName

SELECT COUNT(1) FROM TableName

SELECT SUM(1) AS 'RowCount' FROM TableName

SELECT si.rows AS 'RowCount'
FROM sys.sysindexes si
WHERE si.id = OBJECT_ID('TableName') AND si.indid < 2

EXEC sp_spaceused @objname=N'TableName', @updateusage=N'TRUE';

SELECT COUNT(@@ROWCOUNT) FROM TableName

Thanks and regards,
Raghavendra SK

Sksamantaray, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 3/25/2012 [Member] Silver | Points: 25

Up
0
Down
Hi Raghavendra SK,
Very nice Reply .
only in the 3rd query one needs to be cautious parameter should not be on a numeric column rather on a character column

SELECT COUNT(5) FROM dimCustomer -- to be used on character columns
Overall numeric column sums up value where as character column count no of rows.

Thanks,
Sanjay

Sksamantaray, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Skraghava on: 3/25/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Sanjay,

Thanks for the reply. Please mark as answer if it is correct.

Regards,
Raghavendra SK

Thanks and regards,
Raghavendra SK

Sksamantaray, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sriramnandha on: 5/19/2012 [Member] Starter | Points: 25

Up
0
Down
SELECT COUNT(*) FROM TABLENAME

SELECT COUNT(1) FROM TABLENAME

HOPE THIS WILL HELP

REGARDS

SRIRAM.R

sriram

Sksamantaray, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ajay.Kalol on: 5/21/2012 [Member] Starter | Points: 25

Up
0
Down
SELECT COUNT(1) FROM Table1

Ajay
ajaypatelfromsanthal.blogspot.in

Sksamantaray, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response