Click here to Skip to main content
15,034,986 members
Articles / Database Development / SQL Server
Tip/Trick
Posted 24 Feb 2011

Tagged as

Stats

25.2K views
4 bookmarked

Loop through all tables in SQL Server

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
25 Feb 2011CPOL
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)

Share

About the Author

pankajupadhyay29
Architect
India India
• An Architect, developer, trainer, and student
• 10 years of experience in Architecture and Development of enterprise applications
• Extensive knowledge in designing and developing Web-based enterprise applications using open source and Microsoft Technologies
• Extensive experience in Angular, AngularJS, ReactJs, NodeJs, JavaScript, ASP.Net, C#, CSS, HTML

Comments and Discussions

 
GeneralRe: My bad! Sometimes I'm stopped from voting by the limit they ... Pin
Manfred Rudolf Bihy27-Feb-11 20:46
professionalManfred Rudolf Bihy27-Feb-11 20:46 
GeneralReason for my vote of 5 Good tip! 5 Pin
Manfred Rudolf Bihy27-Feb-11 20:44
professionalManfred Rudolf Bihy27-Feb-11 20:44 
GeneralThanks for that useful tip! 5+ Pin
Manfred Rudolf Bihy25-Feb-11 3:31
professionalManfred Rudolf Bihy25-Feb-11 3:31 
GeneralRe: i think u forget to vote.. ha ha :) Pin
pankajupadhyay2925-Feb-11 4:03
professionalpankajupadhyay2925-Feb-11 4:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.