-
Can primary key, foreign key cross schema? Why or why not?
For example: I have a table STUDENT under schema TEST with a primary key. And I have another table STUDENT1 under schema TEST1. Now I wanted to create a foreign key in table student1 reference test.student. Is this doable?
Thanks!
-
Hi,
There is no problem creating a foreign key contraint from one schema to another providing the required privileges are granted.
Regards
-
I thought so too. But the truth is: after I test it, it did not work. The error message is ora-00942: the referenced table test.student does not exist. user test1 has dba privs.
-
Hi,
I think you may need to grant the privileges directly.
Regards
-
What do you mean by 'grant the privileges directly'?
-
Hi,
Heres an example
Schema Test1 has table employess
Schema Test2 has table departments
grant references, select on test2.departments to test1;
then create the foreign key contraint from employess to departments.
Regards
-
Thanks, Jovery!
After I grant the specific privs, it worked. The question is: why? Why dba privs does not work?
The second question is: Can primary key, foreign key constraint cross database? For example, using database link?
Why or why not?
Thanks a lot!