Skip to content

Listing all tables in a database and their row counts and sizes

'To get the number of rows in a single table we can use the COUNT(*) or COUNT_BIG(*) functions, e.g.

SELECT COUNT(*) FROM Sales.Customer

This is quite straightforward for a single table, but quickly gets tedious if there are a lot of tables. Here are a few ways of listing all the tables that exist in a database together with the number of rows they contain. '...

https://www.sqlmatters.com/Articles/Listing%20all%20tables%20in%20a%20database%20and%20their%20row%20counts%20and%20sizes.aspx

Adding a db_executor role

'SQL Server has several fixed database roles such as db_datareader and db_datawriter, which grants the user read and write access respectively to all the tables in the database. Curiously there is no role to grant a user permission to execute stored procedures, but fortunately this is easily resolved by creating a new role.

The following SQL creates the new role in a database, and then grants it execute rights :

-- Create a db_executor role
CREATE ROLE db_executor

-- Grant execute rights to the new role
GRANT EXECUTE TO db_executor'...

https://www.sqlmatters.com/Articles/Adding%20a%20db_executor%20role.aspx