Solved

FK / PK relationships across databases?

Posted on 2013-01-14
3
333 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 66

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

707 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