Click here to Skip to main content
15,924,318 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to create foreign key in different schema in oracle
Posted
Comments
Member 10423974 26-Nov-13 21:56pm    
Error comes for " table or view does not exist "

The below query .


ALTER TABLE TRAINING_MASTER
ADD CONSTRAINT MyTable_ForeignTableID_fk FOREIGN KEY (
REG_ID
) REFERENCES TESTNEW.TRAINING_MASTER(
REG_ID
)
/

TWO USERS

First User EBMSPTS second user TESTNEW...

TABLE NAME TRAINING_MASTER

GRANT REFERENCES ON TESTNEW.TRAINING_MASTER TO TESTNEW;

*** success

ALTER TABLE TRAINING_MASTER
ADD CONSTRAINT MyTable_ForeignTableID_fk FOREIGN KEY (
REG_ID
) REFERENCES TESTNEW.TRAINING_MASTER(
REG_ID
)
/

*** Error for " ORA-00942: table or view does not exist "
 
Share this answer
 
Comments
Jörgen Andersson 27-Nov-13 8:16am    
You should have used GRANT REFERENCES ON TESTNEW.TRAINING_MASTER TO EBMSPTS;
First you need to fix the grants, obviously using a user with rights to do so:
SQL
GRANT REFERENCES ON TheOtherSchema.TheOtherTable TO MySchemaUser

Then you add the constraint on your table
SQL
ALTER TABLE MyTable
  ADD CONSTRAINT MyTable_ForeignTableID_fk FOREIGN KEY (
    ForeignTableID
  ) REFERENCES TheOtherSchema.TheOtherTable(
    ForeignTableID
  )
/
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900