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 8137341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:05:11+00:00 2026-06-06T11:05:11+00:00

I have nine different databases representing companies, all on the same SQL server 2008

  • 0

I have nine different databases representing companies, all on the same SQL server 2008 machine.

In each company database, there is a view called gltrxdet_vw. This is defined across multiple tables, and I can do a

SELECT x, y, z, SUM(amt) AS amt_ 
FROM gltrxdet_vw
WHERE trxdate BETWEEN '2012-04-01' AND '2012-04-30'
GROUP BY x, y, z

which returns results very quickly due to indexes on the table based on trxdate.

For our consolidated accounts, we need to group across the nine companies so my plan was to create a view which is effectively

CREATE VIEW mcomp_gltrxdet_vw AS
 SELECT x, y, z, trxdate, amt
 FROM companydb1..gltrxdet_vw
  UNION ALL
 SELECT x, y, z, trxdate, amt
 FROM companydb2..gltrxdet_vw
  UNION ALL
...
  UNION ALL
 SELECT x, y, z, trxdate, amt
 FROM companydb9..gltrxdet_vw

So in theory now I can write a query which is

SELECT x, y, z, SUM(amt) AS amt_
FROM mcomp_gltrxdet_vw
WHERE trxdate BETWEEN '2012-04-01' AND '2012-04-30'
GROUP BY x, y, z

x, y and z are fields with transactional info (in reality there will be many more of these and a more complex WHERE condition passed to the query but for the purposes of illustration I hope the above will suffice)

My question is: will SQL Server correctly apply the WHERE condition to the underlying views one at a time before consolidating the results? Or will it be churning for ages building a mega-table before applying the trxdate filter? with very little data in my tables I can’t be sure if this solution will scale correctly. Does it make any difference that I’m querying across different databases?

On a related note, I’m sure some of the responses will be to check the query plans – can anyone link to a decent tutorial of where these tools can be found/how to work them? Been thrown in at the deep end with SSMS (more used to MySQL command line!)

Thanks in advance

  • 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-06T11:05:12+00:00Added an answer on June 6, 2026 at 11:05 am

    Basically, this union-all pattern in views is what’s called (distributed) partitioned views and SQL Server has great support for it. The query optimizer will deal with this just fine.

    Anyway, I recommend you look at the execution plan to make sure. I’m adding the link given by Ed Harper in the comments to this answer as it is helpful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have nine applications within the same Visual Studio solution. All get deployed via
I have a set of XML documents that all share the same schema. (They're
I have a textarea in which the user enters the following data: Paul:Nine, Rome
Have deployed numerous report parts which reference the same view however one of them
I have an array(list?) in ruby: allRows = [start,one,two,start,three,four,start,five,six,seven,eight,start,nine,ten] I need to run a
I have a few arrays of the same length. I want to sort the
Hello i have a app which makes 3 wheels from 3 different arrays of
I have a radio group with two radiobuttons. each button has a custom selector.
I'm at a bit of a loss with this one, I have a nine
I have a data frame in which each column is a time series of

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.