What are the problems with a join between two tables in two different databases?

后端 未结 5 1011
死守一世寂寞
死守一世寂寞 2021-01-01 13:05

I am interested in your thoughts about the the pitfalls of joining two or more tables from different databases. I\'ll try to give an example.

Suppose table Tab

5条回答
  •  执念已碎
    2021-01-01 13:22

    Some general themes re cross-database joins:

    Foreign keys

    As others have pointed out, in the absence of foreign keys, you'll need to roll your own referential integrity. Not a problem in itself, but issues can surface when you're not in control of the data in one or more of the databases.

    A related issue is the use of CASE tools. When reverse-engineering a schema, they will overlook links between tables where a FK->PK relationship doesn't exist.

    Performance

    If the database are on different servers then you're exposed to the vagaries of whatever else is running on those servers as well as the cost of running the join operation itself. Again, if the servers are all within your control, this is something you can monitor but this may may not be the case.

    Coupling

    If your solution relies on other databases you have multiple points of failure. If a database goes down, this could cascade to one or more systems.

    Data modification

    Your solution may be coupled to what you believe to be static data in tables on another database. However, what if this were accidentally (or purposefully) amended, duplicated or deleted. Again, if the databases in question are out of your remit, other teams/departments may not be aware of how your system operates.


    All this being, true, there are many cases where cross-database joins are the norm. A few examples I've seen:

    Mart-Repository

    Performant operations take place on the mart whilst the master data stash is kept on the repository. CRUD operations take place between the two on a frequent or infrequent basis (nightly update, real-time etc).

    Legacy DB

    You might expose a legacy database for data migration and or reporting/auditing purposes.

    Lookup

    One or more of your databases may contain static lookup information which can be re-used.


    So to answer your question - it depends on what exactly you're doing and whether the risk is acceptable. Other solutions exist such as replication but again, how feasible this is will depend on the structure of your department/company.

提交回复
热议问题