簡體   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