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
 query across all databases

Author  Topic 

tpiazza55
Posting Yak Master

162 Posts

Posted - 2011-05-12 : 14:23:33
I have a query

select * from table1

How do i write one query that will excute the above across all the databases?

tmaiden
Yak Posting Veteran

86 Posts

Posted - 2011-05-12 : 17:21:54
sp_msforeachdb @command1='USE ?;SELECT * from table1'
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2011-05-13 : 06:46:47
i shudder to think WHY you would need to do such a thing....

http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page
   

- Advertisement -