SQL count rows in a table

Federico Capece picture Federico Capece · Mar 7, 2015 · Viewed 132.7k times · Source

I need to send a SQL query to a database that tells me how many rows there are in a table. I could get all the rows in the table with a SELECT and then count them, but I don't like to do it this way. Is there some other way to ask the number of the rows in a table to the SQL server?

Answer

CyberDude picture CyberDude · Mar 7, 2015

Yes, SELECT COUNT(*) FROM TableName