Oracle 表引用另一个架构中的表

发布于 2025-01-02 05:17:54 字数 889 浏览 7 评论 0原文

当涉及到多模式设置时,我无法理解 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?这可能吗?

I'm having some trouble understanding what's possible and what's not possible in Oracle when it comes to multi-schema setups. Let's say I have two schemata A and B:

-- 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
);

But the above statement causes

ORA-01031: insufficient privileges

How can I make a table from one schema reference a table from another schema? Is there some GRANT still missing? Is this even possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不羁少年 2025-01-09 05:17:54

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

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 语句之后执行... ...以上操作才能工作。

There are 2 different kinds of privileges: System privs & object privs.

GRANT ALL PRIVILEGES TO user;

will grant all system privs to the user and should be used very very carefully!

GRANT ALL ON table TO user;

will grant SELECT, INSERT etc on a table (ie an object) to the user.

So you'll need to do a...

GRANT ALL ON a.referenced_table TO b;

...after the CREATE TABLE A.REFERENCED_TABLE statement for the above to work.

梦言归人 2025-01-09 05:17:54

对于大多数企业环境来说,授予一切都太过分了。请改用格兰特参考文献。

将 schema.tablename 上的引用授予 target_schema 或 user;

Grant all is too much for most enterprise environments. Use Grant references instead.

Grant references on schema.tablename to target_schema or user;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文