不使用模式名称访问表 [英] Accessing table without using schema name

查看:14
本文介绍了不使用模式名称访问表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 DB2 新手.

如果不使用架构名称,我无法从表中获取数据.如果我使用带有表名的架构名称,我可以获取数据.

I am not able to get data from a table without using the schema name. If I use a schema name with table name, I am able to fetch data.

例子:

SELECT * FROM TABLE_NAME;

它给了我错误,而

SELECT  FROM SCHEMA_NAME.TABLE_NAME;

正在获取结果.

我必须设置什么才能不必总是使用架构名称?

What do I have to set up not to always have to use the schema name?

推荐答案

默认情况下,您的用户名用作不合格对象名称的架构名称.您可以查看当前架构,例如值当前模式.您可以使用 SET SCHEMA new_schema_name 或通过例如一个 JDBC 连接参数.大多数查询工具还可以指定/更改当前架构.

By default, your username is used as the schema name for unqualified object names. You can see the current schema with, e.g. VALUES CURRENT SCHEMA. You can change the current schema for you current session with SET SCHEMA new_schema_name, or via e.g. a JDBC connection parameter. Most query tools also have a place to specify/change the current schema.

请参阅 SET SCHEMA 的手册页 https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.sql.ref.doc/doc/r0001016.html

See the manual page for SET SCHEMA https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.sql.ref.doc/doc/r0001016.html

不合格对象限定的完整规则在这里 https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.sql.ref.doc/doc/r0000720.html#r0000720__unq-alias

The full rules for the qualification of unqualified objects is here https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.sql.ref.doc/doc/r0000720.html#r0000720__unq-alias

例如

不合格的别名、索引、包、序列、表、触发器和视图名称由默认架构隐式限定.

Unqualified alias, index, package, sequence, table, trigger, and view names are implicitly qualified by the default schema.

但是,如果您希望能够在不考虑 CURRENT SCHEMA 值的情况下引用它,则可以为表、模块或序列创建一个公共别名.https://www.ibm.com/support/knowledgecenter/SSEPGG_11.5.0/com.ibm.db2.luw.sql.ref.doc/doc/r0000910.html

However, you can create a public alias for a table, module or sequence if you wish to be able to reference it regardless of your CURRENT SCHEMA value. https://www.ibm.com/support/knowledgecenter/SSEPGG_11.5.0/com.ibm.db2.luw.sql.ref.doc/doc/r0000910.html

(P.S. 以上所有内容均假设您使用的是 Db2 LUW)

(P.S. all the above assumes you are using Db2 LUW)

这篇关于不使用模式名称访问表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆