繁体   English   中英

Oracle表引用另一个模式中的表

[英]Oracle table referencing a table from another schema

在涉及多模式设置时,我很难理解Oracle中可能发生的事情和不可能发生的事情。 假设我有两个模式AB

-- with user SYS connect as SYSDBA
-- note: ALL PRIVILEGES are granted for simplicity in the scope of this question.
--       real life databases would have more fine-grained grants...
create user A identified by A;
grant all privileges to A;

create user B identified by B;
grant all privileges to B;

-- with user A
create table A.REFERENCED_TABLE (
  ID number(7) not null,
  constraint REFERENCED_TABLE_PK primary key (ID)
);

-- with user A or B
create table B.REFERENCING_TABLE (
  A_ID number(7) not null,
  constraint REFERENCING_TABLE_FK 
    foreign key (A_ID) 
    references A.REFERENCED_TABLE(ID)
    on delete cascade
);

但是以上陈述导致

ORA-01031: insufficient privileges

如何使一个方案中的表引用另一个方案中的表? 是否还缺少一些GRANT 这甚至可能吗?

有两种不同类型的特权:系统特权和对象特权。

GRANT ALL PRIVILEGES TO user;

将授予用户所有系统特权,使用时应非常小心!

GRANT ALL ON table TO user;

将向用户授予对表(即对象)的SELECT,INSERT等权限。

所以你需要做一个...

GRANT ALL ON a.referenced_table TO b;

...在CREATE TABLE A.REFERENCED_TABLE语句之后才能使上述代码正常工作。

对于大多数企业环境而言,全部授予过多。 请改用Grant引用。

将对schema.tablename的引用授予给target_schema或用户;

暂无
暂无

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

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