引用另一个架构的外键 [英] Referencing the foreign key of another schema

查看:58
本文介绍了引用另一个架构的外键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的项目,我使用的是oracle数据库,其中必须使用2种不同的数据库架构。请考虑以下情形-

For my project I am using oracle database where I have to work with 2 different database schema. Consider the following scenario please -

我有一个架构 A ,其中有一个表 table_a 和主键 apk

I have a schema A and in it I have a table table_a with a primary key apk

我还有另一个模式 B ,其中有一个主键为 bpk table_b >

And I have another schema B and in it I have a table table_b with a primary key bpk

如果这两个表都在同一个数据库中,那么我可以轻松地建立主键-外键关系。

If both of these tables are in a same database then I can easily make a primary key - foreign key relationship.

但是我能否在这两列之间创建主键-外键关系(或类似的东西)- A.table_a.apk B.table_b.pbk

But can I make a primary key - foreign key relation ship (or something like this) between these two columns - A.table_a.apk and B.table_b.pbk.

预先感谢。

推荐答案

要创建引用不同模式中的对象的外键,只需限定对象名称

To create a foreign key that references an object in a different schema, you just need to qualify the object name

ALTER TABLE B.table_b
  ADD CONSTRAINT fk_b_a FOREIGN KEY (apk) REFERENCES a.table_a( apk )

这还要求用户 B 对<$具有足够的特权c $ c> A.table_a 。用户将需要具有 REFERENCES 特权,并且可能需要在表上具有 SELECT 特权,如下所示:好吧。

This also requires that the user B has sufficient privileges on A.table_a. The user would need to have the REFERENCES privilege and would, presumably, need to have the SELECT privilege on the table as well.

这篇关于引用另一个架构的外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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