繁体   English   中英

对新架构的外键引用

[英]Foreign key reference to a new schema

我想将一些表移动到新的架构。 移动它时,外键引用出现错误。 我也尝试授予权限。 帐户是地址表所在的旧模式,我将地址移到了称为地址的新模式。 我得到错误表或视图不存在:

CREATE TABLE ACCOUNTS.PARTY_ADDRESS
(
 PARTY_ID NUMBER(18,0),
 ADDRESS_ID NUMBER(18,0),
 CONSTRAINT PARTY_ADDRESS_PK PRIMARY KEY (PARTY_ID, ADDRESS_ID),
 constraint PARTY_ADDRESS_party_fk foreign key (PARTY_ID)
 references PARTY(id),
 constraint PARTY_ADDRESS_ADDRESS_UNQ unique (ADDRESS_ID)
);

ALTER TABLE ACCOUNTS.PARTY_ADDRESS ADD CONSTRAINT PARTY_ADDRESS_address_fk FOREIGN KEY (ADDRESS_ID) REFERENCES ADDRESS.ADDRESS(id);

我还提供了以下地址的赠款:

GRANT ALL ON ADDRESS.ADDRESS TO ACCOUNTS;

REFERENCES一个架构能够创建对另一个架构中的表的引用约束,必须具有表特权REFERENCES GRANT ALL应该已经工作了。 在我的测试案例中,它确实有效,例如:

模式1:

create table schema1.t1 (id number primary key);

Table T1 created.

模式2:

create table schema2.t2 (id number primary key, fk number);

Table T2 created.

alter table schema2.t2 add constraint fktest
  foreign key (fk) references schema1.t1 (id);

ORA-00942: table or view does not exist

模式1:

grant references on schema1.t1 to schema2;

Grant succeeded.

模式2:

alter table schema2.t2 add constraint fktest
  foreign key (fk) references schema1.t1 (id);

Table T2 altered.

模式1:

revoke references on schema1.t1 from schema2;

ORA-01981: CASCADE CONSTRAINTS must be specified to perform this revoke

revoke references on schema1.t1 from schema2 cascade constraints;

Revoke succeeded.

如果您GRANT ALL它也可以使用:

模式1:

grant all on schema1.t1 to schema2;

Grant succeeded.

模式2:

alter table schema2.t2 add constraint fktest
  foreign key (fk) references schema1.t1 (id);

Table T2 altered.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM