Groups | Blog | Home
all groups > sql server mseq > september 2007 >

sql server mseq : Run same query against multiple tables


Gav
9/10/2007 7:24:07 AM
Hi all,

Is there a way to quickly run an sql query against all the tables in a
database? or will I have to simply write a line for each table? I have 100+
tables where I want to delete rows from from them where ID= (a particular id).

Thanks
Russell Fields
9/10/2007 1:17:58 PM
Gav,

There is the undocumented stored procedure: sp_msforeachtable

It will execute the command specified for the databases on your server. It
is fairly flexible, but (as mentioned) is undocumented and therefore
unsupported. You can also look at the code to see how it is doing the work
and then imitate that in your own code.

RLF

[quoted text, click to view]

Gav
9/11/2007 12:52:00 AM
That's great just what I was looking for, thank you RLF.

Regards
Gav

[quoted text, click to view]
AddThis Social Bookmark Button