0

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?

user246160
  • 1,389
  • 7
  • 18
  • 33

2 Answers2

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
0
SELECT COUNT(*) FROM <YOURTABLE>
hallie
  • 2,760
  • 19
  • 27