views:

19

answers:

3

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?

+1  A: 

Start here

ck
A: 
SELECT COUNT(*) FROM <YOURTABLE>
hallie
+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
@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
@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