How to get the list of the tables in my sql-server database that do not have any records in them?
How to get the list of the tables in my sql-server database that do
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
On SQL Server 2005 and up, you can use something like this:
The inner select in the CTE (Common Table Expression) calculates the number of rows for each table and groups them by table (
OBJECT_ID), and the outer SELECT from the CTE then grabs only those rows (tables) which have a total number of rows equal to zero.UPDATE: if you want to check for non-Microsoft / system tables, you need to extend the query like this (joining the
sys.tablescatalog view):