Oracle 在不同架构上使用相同的表名?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1685775/
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 19:22:31  来源:igfitidea点击:

Oracle same table name on different schema?

databaseoracleschema

提问by Dels

Is it possible to have same table name on different schema with different data on the tables within the one database? I think rather than create multiple database (that hold same table name) i should create multiple schema instead.

是否可以在一个数据库中的表上具有不同数据的不同架构上具有相同的表名?我认为与其创建多个数据库(保存相同的表名),不如创建多个模式。

Something like:

就像是:

Schema 1:
  table A, table B
Schema 2:
  table B, table X

PS: table B hold different data for each schema

And most basic question did every schema (user) hold different table set? In SQL Server and MySQL every user on same database have same table set, the difference was only on roles, how about Oracle?

最基本的问题是每个模式(用户)都持有不同的表集吗?在 SQL Server 和 MySQL 中,同一数据库上的每个用户都有相同的表集,区别仅在于角色,Oracle 怎么样?

Thanks

谢谢

回答by Hymanrabbit

Yes this is possible. A schema in Oracle is what a MySQL user would call a database.

是的,这是可能的。Oracle 中的模式就是 MySQL 用户所说的数据库。

However, you need to be careful when accessing either of the tables now if the user you connect with to the database instance has access to both. To unambiguously reference a table in a specific schema, use schema.table.

但是,如果您现在连接到数据库实例的用户可以访问这两个表,则在访问其中一个表时需要小心。要明确引用特定模式中的表,请使用schema.table.

回答by David Aldridge

Here's the documentation on namespaces: http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/sql_elements008.htm#i27561

这是关于命名空间的文档:http: //download.oracle.com/docs/cd/E11882_01/server.112/e10592/sql_elements008.htm#i27561

As Hymanrabbit says objects in different schemas have different namespaces.

正如 Hymanrabbit 所说,不同模式中的对象具有不同的命名空间。

Each schema in the database has its own namespaces for the objects it contains. This means, for example, that two tables in different schemas are in different namespaces and can have the same name.

数据库中的每个模式对于它所包含的对象都有自己的命名空间。这意味着,例如,不同模式中的两个表位于不同的命名空间中并且可以具有相同的名称。

Within a schema things are a little more complex.

在模式中,事情稍微复杂一些。

Because tables and views are in the same namespace, a table and a view in the same schema cannot have the same name. However, tables and indexes are in different namespaces. Therefore, a table and an index in the same schema can have the same name.

由于表和视图在同一个命名空间中,因此同一架构中的表和视图不能具有相同的名称。但是,表和索引位于不同的命名空间中。因此,同一模式中的表和索引可以具有相同的名称。