hi i created project using asp.net and sql server 2005.I created table and inserted datainto sqlserver 2005. but i dont how to find the(count) number of records stored in the table.how to find this?
Asked
Active
Viewed 123 times
0
-
[Start here](http://www.w3schools.com/sql) – cjk Mar 16 '10 at 08:55
2 Answers
2
Use
SELECT COUNT(PrimaryKeyColumn) FROM YoutTableName
Never use Count(*).
Also, you can use sysindexes table to get the row count of a table. Read here.

Ashish Gupta
- 14,869
- 20
- 75
- 134
-
@Ashish: I'm interested to know why you say "never use count(*)", what basis do you have for saying that? Here's a related question on SO: http://stackoverflow.com/questions/1221559/count-vs-count1 – Tony Mar 16 '10 at 09:53
-
@Tony, thanks. Will strikeout when I am done analysing. There is a table in my db which has 136001 rec and I ran the following on it DBCC DROPCLEANBUFFERS go SET STATISTICS IO ON SELECT COUNT(Id) FROM base SELECT COUNT(*) FROM base SET STATISTICS IO OFF (1 row(s) affected) Table 'Base'. Scan count 1, logical reads 673, physical reads 3, read-ahead reads 669, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. Table 'Base'. Scan count 1, logical reads 673, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. – Ashish Gupta Mar 16 '10 at 10:21