Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Foreign keys in alternate schemas with Oracle?

I have two schemas, let's call them BOB and FRED. I need to call a table in schema FRED from schema BOB to use the primary key in that table as a foreign key. I've set up the appropriate grants for schema FRED to allow BOB access to it, but whenever I run the script, it complains that I do not have the correct permissions. Is there another setting that I need to change somewhere? Can this even be done?

My FK creation is as follows:

ALTER TABLE "BOB"."ITEMGROUP" WITH CHECK ADD CONSTRAINT FK_ITEMS_ITEM FOREIGN KEY (ItemID)
REFERENCES "FRED"."ITEMS"(ItemID)

And I'm doing the grant with:

GRANT ALTER ON "FRED"."ITEMS" TO "BOB"

I get this error message:

SQL Error: ORA-01031: insufficient privileges 
01031. 00000 -  "insufficient privileges"

*Cause:    An attempt was made to change the current username or password
           without the appropriate privilege. This error also occurs if
           attempting to install a database without the necessary operating
           system privileges.
           When Trusted Oracle is configure in DBMS MAC, this error may occur
           if the user was granted the necessary privilege at a higher label
           than the current login.

*Action:   Ask the database administrator to perform the operation or grant
           the required privileges.
           For Trusted Oracle users getting this error although granted the
           the appropriate privilege at a higher label, ask the database
           administrator to regrant the privilege at the appropriate label.
like image 682
Skulmuk Avatar asked Aug 30 '12 14:08

Skulmuk


People also ask

Can we have two foreign keys in a table in Oracle?

A table can have multiple foreign keys based on the requirement.

How does foreign key work in Oracle?

A foreign key relationship involves a parent table that holds the initial column values, and a child table with column values that reference the parent column values. A foreign key constraint is defined on the child table.

Can a foreign key be a foreign key in another table?

In a foreign key reference, a link is created between two tables when the column or columns that hold the primary key value for one table are referenced by the column or columns in another table. This column becomes a foreign key in the second table.

What is foreign key in schema?

A FOREIGN KEY is a field (or collection of fields) in one table, that refers to the PRIMARY KEY in another table. The table with the foreign key is called the child table, and the table with the primary key is called the referenced or parent table.


1 Answers

You need to:

grant references on "FRED"."ITEMS" TO "BOB"

See this "AskTom"

like image 70
A.B.Cade Avatar answered Oct 19 '22 05:10

A.B.Cade