简体   繁体   English

Oracle相当于SQL Server SCHEMA

[英]Oracle equivalent of SQL Server SCHEMA

I have a task to migrate a SQL Server database to Oracle. 我有一项任务是将SQL Server数据库迁移到Oracle。

There are several different SCHEMAs in our SQL Server database and I have to create something similar in Oracle. 我们的SQL Server数据库中有几个不同的SCHEMA,我必须在Oracle中创建类似的东西。 In SQL Server SCHEMA is like a namespace in C#. 在SQL Server中,SCHEMA就像是C#中的命名空间。 But as far as could understand from the Oracle docs, Schema in Oracle has quite a different meaning from that in SQL Server. 但是从Oracle文档中可以理解,Oracle中的Schema与SQL Server中的Schema有着截然不同的含义。

To be more specific, I have the following SQL statement in SQL Server: 更具体地说,我在SQL Server中有以下SQL语句:

CREATE SCHEMA Accounting

CREATE TABLE [Accounting].[Payments]
(
    ID BIGINT,
    Amount MONEY
)

So what is the equivalent of this script in Oracle? 那么Oracle中这个脚本的等价物是什么?

The Oracle equivalent of a SQL Server schema is, well, a schema. Oracle等效的SQL Server架构就是一个架构。 An Oracle server talks to a single database and that is the "real" difference between the two: A SQL Server instance can connect to multiple databases whereas an Oracle instance connects directly to only one. Oracle服务器与单个数据库进行通信,这是两者之间的“真正”区别:SQL Server实例可以连接到多个数据库,而Oracle实例只能连接到一个数据库。 Because of this, SQL Server uses a three-part naming convention within a server and Oracle only has a two-part naming convention. 因此,SQL Server在服务器中使用三部分命名约定,而Oracle仅具有两部分命名约定。

In both, schema objects are generally speaking the unit of security -- they are convenient for assigning permissions to groups of objects. 在两者中,模式对象通常都是安全单元 - 它们便于为对象组分配权限。 The two databases differ on some very important points. 两个数据库在一些非常重要的问题上有所不同 In Oracle, a schema is essentially synonymous with a user. 在Oracle中,模式本质上是用户的同义词。 SQL Server was once organized this way, but now a schema is separate from users (allowing objects to be moved between schemas for instance). SQL Server曾经以这种方式组织,但现在一个模式与用户分开(例如,允许在模式之间移动对象)。

In SQL Server, permissions do not have to be at the schema level, although that is often convenient for organizational purposes. 在SQL Server中,权限不必位于架构级别,尽管这通常可以方便用于组织目的。 For instance, you might have underlying tables that users have no direct access to in one schema. 例如,您可能拥有用户在一个架构中无法直接访问的基础表。 You can have another schema with views and the schema has permissions to access the tables. 您可以拥有另一个包含视图的模式,并且模式具有访问表的权限。 Then, a new view added to the schema automatically has the "right" permissions. 然后,添加到架构的新视图会自动具有“正确”权限。

While @Gordon Linoff 's answer is pretty much perfect explanation of the idea behind schemas in both databases, to answer your practical problem: 虽然@Gordon Linoff的答案非常完美地解释了两个数据库中模式背后的想法,但是要回答你的实际问题:

You create a schema as a user: 您以用户身份创建架构:

CREATE USER Accounting IDENTIFIED BY some_password;

And then create objects in that schema with: 然后使用以下命令在该模式中创建对象:

CREATE TABLE Accounting.Payments
(
  ID NUMBER(19),
  Amount NUMBER(19,4)
)

A historical note that helps explain some of the confusion: Up to MS SQL Server 2000, Schema meant nearly the same thing as in Oracle. 一个历史记录,有助于解释一些混淆:直到MS SQL Server 2000,Schema意味着几乎与Oracle相同。 And MS SQL Server was based on Sybase SQL Server, which was also perhaps more similar to Oracle. MS SQL Server基于Sybase SQL Server,也可能与Oracle更相似。 Then by 2005, MS took away the binding between user and schema, though a default schema name like dbo is based on a user name. 然后到2005年,MS取消了用户和架构之间的绑定,尽管像dbo这样的默认架构名称基于用户名。

Good answer is in the DBA Stack Forum: What is the difference between an Oracle and Microsoft schema? DBA堆栈论坛的答案很好: Oracle和Microsoft架构有什么区别?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM