Is it possible to implement a foreign key constraint in a database that resides in another Oracle database instance? If so, could you explain how?
Foreign Key constraints cannot be forced across a database link. This makes sense if your network connections go down or the remote database becomes unavailable. Constraints should not be violated due to network problems or other databases going down.
You can however force this yourself, but you will have to do some coding. You can create a trigger on a table. On INSERT into that table, make sure the the parent inserts in the table across the database link. If it does not exist in that remote table, then throw an exception. Otherwise, do nothing. So your solution is to code triggers to handle the constraint for you.
For More Information
- Dozens more answers to tough Oracle questions from Brian Peasland are available.
- The Best Oracle Web Links: tips, tutorials, scripts, and more.
- Have an Oracle or SQL tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
- Ask your technical Oracle and SQL questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.
Dig Deeper on Oracle database design and architecture
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.