Solved

FK / PK relationships across databases?

Posted on 2013-01-14
3
329 Views
Last Modified: 2013-01-15
I have an MS SQL 2008 R2 instance. There are 3 databases; I will say db_1, db_2 and db_3. I want db_2 to hold all the common information like users, email addresses, and some other metadata, then the other 2 db's will be for 2 separate front end transactional applications. Is there a way to enforce PK / FK constraints across databases in the same MS SQL server instance?
0
Comment
Question by:sqlagent007
3 Comments
 
LVL 16

Assisted Solution

by:Kamal Khaleefa
Kamal Khaleefa earned 100 total points
ID: 38777096
hi
i think it would be very difficult because your tables are in different databases

i suggest either to put all your tables in one database and do the PK/FK

or keep the design as it is and control every thing from you Code( to do insert / update /delete)
0
 
LVL 65

Accepted Solution

by:
Jim Horn earned 400 total points
ID: 38778098
>Is there a way to enforce PK / FK constraints across databases
No.  relationships are within a database only.

The closest you can get, and even this is somewhat of a house of cards, would be to write trigger code in one_db.one_table, testing to see if the ID is unique compared to other_db.other_tables, and if not either denying the insert or changing the ID.
0
 
LVL 1

Author Closing Comment

by:sqlagent007
ID: 38778590
Thanks experts!!!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This video teaches users how to migrate an existing Wordpress website to a new domain.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question