简体   繁体   中英

Selecting and aggregating data from multiple databases

I'm looking for some advice, so apologies if this is the wrong section (I will delete and post in DB Administrators if that is more appropriate).

I have an application that manages legal cases. Each law firm has its own database for managing their own cases and other business processes. Therefore there can be potentially hundreds of databases in total.

A citizen may have cases with many law firms. Some of these cases are in various "stages" of their life (see below for example)

I want my application to show the user an aggregation of all their cases in total, by stage and status. So to the user it will look like something from an email client:

Cases (15)
  Open (10)
   Under Examination (4)
   Escalated (6)
  Closed (5)

To get these numbers I have to select all their cases from each database for each law firm this user has a case with. In pseudo-code I'll have to:

SELECT 
 c1.Title, c1.Stage
FROM 
 [@DatabaseName].dbo.Cases c1 
WHERE 
 c1.CustomerID = @CustomerUserID

It has to do this for EACH database (potentially 50+) and then UNION all the results together to get a total for all Open cases, by Stage , that this citizen has.

The only other way I can think of to make this simpler is to not have a multi-tennant architecture. That is, just have 1 table for Cases in 1 database which has a column to identify which law firm it belongs to. The problem is that this solution won't scale well if the application grows into other areas such as HR or Finance etc. It will mean that I will have to store the entirety of every law firms data in 1 database which will kill my server and resources.

Is there a better way to tackling this?

Check Azure Elastic Scale Api

This provides APIs to handle multiple shards using a shard management database.

You can create a shard for Each Law Firm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM