How to count or know the number of rows a table has without scaning all the table, maybe using ROW_NUMBER?
There is no ROW_NUMBER in SQL Server, just Oracle. Use:
SELECT COUNT(primary_key) FROM table
Where primary key the primary key column of your table.
Since its a primary key, its is already indexed, so SQL can count it without scanning the whole table (it uses a clustered index to be precise, which is much faster than a full table scan)
You could also use sys.indexes schema, but its not accurate, and you would need database admin priviledges to access, and your application database user is not supposed to have grants in that schema