Loop through all tables in SQL Server





5.00/5 (4 votes)
Use this when you want to perform a task on all tables in a database
sp_MSforeachtable
is a stored procedure used to loop through all the tables in the database. We can use this in different situations. For example, we want to run command to disable all triggers, then we could write that like this:
sp_msforeachtable "ALTER TABLE ? DISABLE TRIGGER all"
? will be replaced with table name.
I think you will enjoy this.
For details, click here[^]