DEV Community

Discussion on: How to Check Which Tables Contain Data in a Database

Collapse
 
stevsharp profile image
Spyros Ponaris

Thanks for sharing! In SQL Server, you can also use sp_MSforeachtable.
The sp_MSforeachtable procedure is an undocumented stored procedure in SQL Server that executes a given command for each table in the database.
Executing the following command returns a list of tables that contain data:
EXEC sp_MSforeachtable 'IF EXISTS (SELECT 1 FROM [?]) PRINT ''Table: ? contains data'''

Collapse
 
msnmongare profile image
Sospeter Mong'are

Thank you Spyros for sharing this. it will be helpful to the community