Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 looping Through tables

Author  Topic 

ann06
Posting Yak Master

171 Posts

Posted - 2008-04-12 : 06:10:50
I want to loop through all tables in a database for the given qeury

SELECT TABLE_NAMe
FROM INFORMATION_SCHEMA.TABLES

how to intialize the counter and what should be the boolean expression
Thank you and Best Regards

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2008-04-12 : 06:50:44
have a look at CURSORS in Books Online



Jack Vamvas
--------------------
Search IT jobs from multiple sources- http://www.ITjobfeed.com
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-04-12 : 10:06:44
ann06, if you're trying to code some admin tasks or simply want to see some good examples of t-sql code, one good place to look is some of the weblogs here - like TKizer's:

http://weblogs.sqlteam.com/tarad/category/95.aspx

"Running my code against multiple databases" has an example of iterating through a result set.

Be One with the Optimizer
TG
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-04-12 : 10:39:53
if I need to run the same script against multiple databases in an automated way, my favorite method is to use SQLCMD and the FOR dos command.

see my post here: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=94068#356331


elsasoft.org
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-12 : 13:54:59
And if you're looking for executing any specific commands on all tables of db you can even use the undocumented system stored procedure sp_Msforeachtable
Go to Top of Page

ann06
Posting Yak Master

171 Posts

Posted - 2008-04-13 : 02:24:30
Thanks for the feeds
Best Regards
Go to Top of Page
   

- Advertisement -