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?
+2
A:
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.
ydobonmai
2010-03-16 09:02:42
@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
2010-03-16 09:53:32
@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 DROPCLEANBUFFERSgoSET STATISTICS IO ONSELECT COUNT(Id) FROM baseSELECT COUNT(*) FROM baseSET 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.
ydobonmai
2010-03-16 10:21:25