Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Run same query against multiple tables

 
   Database Forums (Home) -> MSEQ RSS
Next:  Help with Current DATE in Query  
Author Message
Gav

External


Since: Apr 05, 2006
Posts: 2



(Msg. 1) Posted: Mon Sep 10, 2007 7:24 am
Post subject: Run same query against multiple tables
Archived from groups: microsoft>public>sqlserver>mseq (more info?)

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
Gav

 >> Stay informed about: Run same query against multiple tables 
Back to top
Login to vote
Russell Fields

External


Since: Feb 21, 2007
Posts: 457



(Msg. 2) Posted: Mon Sep 10, 2007 1:17 pm
Post subject: Re: Run same query against multiple tables [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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

"Gav" wrote in message

> 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
> Gav

 >> Stay informed about: Run same query against multiple tables 
Back to top
Login to vote
Gav

External


Since: Apr 05, 2006
Posts: 2



(Msg. 3) Posted: Tue Sep 11, 2007 12:52 am
Post subject: Re: Run same query against multiple tables [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

That's great just what I was looking for, thank you RLF.

Regards
Gav

"Russell Fields" wrote:

> 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
>
> "Gav" wrote in message
>
> > 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
> > Gav
>
>
>
 >> Stay informed about: Run same query against multiple tables 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Query returning multiple rows - Hi, I have a query that returns back rows that have multiple entries for a given UniqueID. I want the query to be expanded so that it then only returns 1 of the multiple rows based on the maximum date. Thefore, my return set looks like this: ..

Query for reordering tables - Hi folks!, I have this table: int char +-----+-------+ | X1 | X2 | +=====+=======+ | 1 | "A" | +-----+-------+ | 1 | "B" | +-----+-------+ | 2 | "C" | +-----+-------+ | 2 | "D" | +-----+--...

Doing multiple joins on one table - I have those Tables: CREATE TABLE GameYellows( id INT NOT NULL AUTO_INCREMENT, AddedDate DATETIME NOT NULL, Player_ID INT NOT NULL, ) CREATE TABLE GameReds( id INT NOT NULL AUTO_INCREMENT, AddedDate DATETIME NOT NULL, Player_ID INT NOT NULL, ) ...

Insert Multiple Rows into a Table Without Using Select - Hi. I want to insert 4 rows into a SQL table. Can I do this without using 4 Insert statements? This is my SQL statement: Insert Into MyTable Values (1,2) (3,4) (5,6)...

GROUP BY's on 3 tables in one SELECT? - Hi there, I'd like to ask you for help with following: having 3 tables: T1 (Person_ID, Product_ID, Costs) T2 (Person_ID, Product_ID, Balancies) T3 (Product_ID, Product_Type) I have simple GROUP BY query: SELECT T1.Person_ID, T1.Product_ID, MAX(Costs)..
   Database Forums (Home) -> MSEQ All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]