Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8701785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:29:10+00:00 2026-06-13T02:29:10+00:00

All… I need a way to query identical tables across multiple databases. I have

  • 0

All… I need a way to query identical tables across multiple databases. I have roughly 30+ databases and they all have identical tables.

    SELECT 
      a.name
      , a.address
      , b.company_id
      , c.part_no
      , c.cost
    FROM accounts a
    JOIN business b on a.whatever = b.whatever
    JOIN crazy c ON b.things = c.things

Something simple like this, but across all databases. The focus isn’t joining on multiple databases, that’s simple, it’s running this across all databases simultaneously. There’s got to be a simpler way than creating a long drawn out stored procedure, no?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:29:11+00:00Added an answer on June 13, 2026 at 2:29 am
    CREATE PROC dbo.alldatabasequery 
    AS 
    
     CREATE TABLE #temp (
     databasename varchar(500),
     name varchar(max),
     address varchar(max),
     company_id varchar(max),
     cost varchar(max)
     )
    INSERT INTO #temp 
     EXEC sp_MSforeachdb N'IF ''?'' NOT IN ( ''model'',''tempdb'',''master'',''msdb'')
      BEGIN 
      SELECT databasename=''?'' 
        , a.name
        , a.address
        , b.company_id
        , c.part_no
        , c.cost
        FROM ?.dbo.accounts a
        JOIN ?.dbo.business b 
        on a.whatever = b.whatever
        JOIN ?.crazy c
        ON b.things = c.things
       END' ; 
    
    SELECT   * FROM #temp 
    
    
    GO 
    
    EXEC dbo.alldatabasequery 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All, If I run a query like the following: $qry = Select wrong_column from
All, I have the following code: $fetch = mysql_query(SELECT * FROM calendar_events where event_status='booked'
All, Say I have the following bit of code: select: function(start, end, allDay) {
All - Need some insight into this issue. I have created a sample project
All, I have developed an export mechanism to allow the selected tables from a
All -- I have these two methods in one of my classes: public static
All my files can be found on GitHub: https://github.com/Integralist/Passage (just in case you need
All, I have the following class so to check to see if the form
All, I have a guestbook feature on my site and I keep getting spammed.
All the examples of use and tutorials I have found on beginBackgroundTaskWithExpirationHandler: show how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.