Oracle SQL Developer Query Connect 作为其他用户

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6291672/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 23:55:35  来源:igfitidea点击:

Oracle SQL Developer Query Connect as Other User

sqloracle

提问by Nick Binnet

I am designing a new database via a new sql file. I am using Oracle SQL Developer and logged in as sysdba.

我正在通过一个新的 sql 文件设计一个新的数据库。我正在使用 Oracle SQL Developer 并以 sysdba 身份登录。

I would like to know if SQL developer supports or has equivalent command to

我想知道 SQL 开发人员是否支持或具有等效的命令

connect scott/tiger;

Thank you in advance.

先感谢您。

Edit

编辑

I am trying to create a foreign key on Schema A table referencing to Schema B table.

我正在尝试在引用架构 B 表的架构 A 表上创建外键。

The error shown is

显示的错误是

[Err] ORA-00942: table or view does not exist

[Err] ORA-00942: 表或视图不存在

I therefore want to login as "Schema B", grant all permission to SYS user, login as sys again and create the relationship.

因此,我想以“架构 B”身份登录,将所有权限授予 SYS 用户,再次以 sys 身份登录并创建关系。

Hope I am clearer this time.

希望这次我更清楚。

采纳答案by DCookie

As the user SYS you should be able to create the relationship you want by simply prefixing object names with schema owner, as mentioned previously:

作为用户 SYS,您应该能够通过简单地在对象名称前加上架构所有者来创建您想要的关系,如前所述:

ALTR TABLE foo.t1 ADD FOREIGN KEY (col) REFERENCES bar.t2(ID);

That said, you must also grant the REFERENCES privilege to the user foo in order to make this relationship:

也就是说,您还必须向用户 foo 授予 REFERENCES 权限才能建立这种关系:

GRANT REFERENCES ON bar.t2 TO foo;

The user SYS should be able to do all this. Whether it's a good practice or not is another question.

用户 SYS 应该能够完成所有这些。这是否是一个好的做法是另一个问题。

回答by Adam Musch

I believe you need to break and re-establish the connection to the database/service in order to log in as a different user in SQL Developer.

我相信您需要断开并重新建立与数据库/服务的连接,以便在 SQL Developer 中以不同用户身份登录。

However, if you simply want to be in the SCOTTuser's name space (so that CREATE TABLE EMP...is executed as CREATE TABLE SCOTT.EMP ..., you can issue

但是,如果您只是想在SCOTT用户的名称空间中(以便CREATE TABLE EMP...作为 执行CREATE TABLE SCOTT.EMP ...,您可以发出

alter session set current_schema = SCOTT;

alter session set current_schema = SCOTT;

回答by Phil

Also remember that if you're trying to create a FK to a table in a different schema & there aren't any synonyms, you have to fully qualify the name:

还请记住,如果您尝试为不同架构中的表创建 FK 并且没有任何同义词,则必须完全限定名称:

eg, as the user SCHEMA_A:

例如,作为用户 SCHEMA_A:

ALTER TABLE SCHEMA_A.TABLE_A
add CONSTRAINT fk_TABLE_B
  FOREIGN KEY (COLUMN_A)
  REFERENCES SCHEMA_B.TABLE_B(COLUMN_B);

You mention use of the SYS user - I hope you're not logging in a SYS to do normal development...

您提到使用 SYS 用户 - 我希望您没有登录 SYS 进行正常开发...