Referencing the foreign key of another schema

岁酱吖の 提交于 2019-12-14 02:16:44

问题


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

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

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.

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.

Thanks in advance.


回答1:


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 )

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.



来源:https://stackoverflow.com/questions/29155012/referencing-the-foreign-key-of-another-schema

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!