两个数据库之间的交叉外键 [英] Cross Forign Key Between Two Database

查看:64
本文介绍了两个数据库之间的交叉外键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我有两个数据库DB1有TBL1,DB2有TBL2
并且我需要[TBL1]表(在DB1数据库中)中的外键是对另一个表[TBL2](在DB2数据库中)的引用.
当我尝试通过SQL创建它们时,收到以下错误消息:



消息1763,级别16,状态0,第1行
不支持跨数据库外键引用.外键"SAMPLEDB..VENDOR".
是否可以在外部数据库中引用外键?

如果可能,请提供解决方案.如果不可能,请提出一些替代方法.

Hi All
I have Two Database DB1 Have TBL1, DB2 Have TBL2
and I need a foreign key in the [TBL1] table (which is in DB1 database) is reference to the other table [TBL2] (which is in the DB2 database).

When i try to creating them through SQL, I received the following error message :



Msg 1763, Level 16, State 0, Line 1
Cross-database foreign key references are not supported. Foreign key ''SAMPLEDB..VENDOR''.
Is that possible to refer foreign key in external database or not?

If possible, please give solution for this. If not possible, please suggest some alternate way.

推荐答案

错误消息非常明显:
不支持跨数据库外键引用"

因此答案就在问题中:否".
The error message is pretty explicit:
"Cross-database foreign key references are not supported"

So the answer is in the question: "No".


正如OG所说,这是不可能的

替代方法是,让您使用用于操纵行的SP进行断言

或在其中放置触发器-我会与第一个触发器一起使用
as OG stated, it''s not possible

Alternatives are, have the SP you use to manipulate the row make the assertion

or put a trigger in there - I''d go with the first one


这篇关于两个数据库之间的交叉外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆