Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / database / SQL-Server

Loop through all tables in SQL Server

5.00/5 (4 votes)
25 Feb 2011CPOL 28.8K  
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:

SQL
sp_msforeachtable "ALTER TABLE ? DISABLE TRIGGER all"

? will be replaced with table name.
I think you will enjoy this.

For details, click here[^]

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)