Oracle 中用户和模式之间的区别?

发布于 2024-07-21 02:18:40 字数 27 浏览 5 评论 0原文

Oracle 中的用户和模式有什么区别?

What is the difference between a user and a schema in Oracle?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(16

昵称有卵用 2024-07-28 02:18:41

模式是对象的容器。
它由用户拥有。

Schema is a container of objects.
It is owned by a user.

只有一腔孤勇 2024-07-28 02:18:41

好吧,我在某处读到,如果您的数据库用户具有 DDL 权限,那么它就是一个架构,否则它就是一个用户。

Well, I read somewhere that if your database user has the DDL privileges then it's a schema, else it's a user.

淡墨 2024-07-28 02:18:40

来自询问 Tom

您应该将模式视为用户帐户和集合
其中的所有对象作为用于所有意图和目的的模式。

SCOTT 是一个包含 EMP、DEPT 和 BONUS 表的架构
各种补助金和其他东西。

SYS 是一个包含大量表、视图、授权等的架构
等等

SYSTEM 是一个模式......

从技术上讲——模式是使用的元数据(数据字典)集
由数据库生成,通常使用 DDL 生成。 模式定义
数据库的属性,例如表、列和属性。
数据库架构是数据库中数据的描述。

From Ask Tom

You should consider a schema to be the user account and collection of
all objects therein as a schema for all intents and purposes.

SCOTT is a schema that includes the EMP, DEPT and BONUS tables with
various grants, and other stuff.

SYS is a schema that includes tons of tables, views, grants, etc etc
etc.

SYSTEM is a schema.....

Technically -- A schema is the set of metadata (data dictionary) used
by the database, typically generated using DDL. A schema defines
attributes of the database, such as tables, columns, and properties.
A database schema is a description of the data in a database.

浅忆 2024-07-28 02:18:40

我认为问题在于 Oracle 使用的术语“架构”与通常的含义略有不同。

  1. Oracle的模式(如Nebakanezer的答案中所解释的):基本上是用户帐户拥有的所有表和其他对象的集合,因此大致相当于用户帐户
  2. 一般模式:组成数据库的所有表、存储过程等的集合对于给定的系统/应用程序(如“开发人员应该与 DBA 讨论我们新应用程序的架构。”)

意义 2 中的架构类似,但与意义 1 中的架构不同。例如,对于使用多个数据库帐户,意义 2 中的模式可能由多个 Oracle 模式组成:-)。

另外,模式还可以表示其他上下文中(例如数学)中的一堆其他相当不相关的事物。

Oracle 应该只使用“userarea”或“accountobjects”之类的术语,而不是重载“schema”...

I believe the problem is that Oracle uses the term schema slightly differently from what it generally means.

  1. Oracle's schema (as explained in Nebakanezer's answer): basically the set of all tables and other objects owned by a user account, so roughly equivalent to a user account
  2. Schema in general: The set of all tables, sprocs etc. that make up the database for a given system / application (as in "Developers should discuss with the DBAs about the schema for our new application.")

Schema in sense 2. is similar, but not the same as schema in sense 1. E.g. for an application that uses several DB accounts, a schema in sense 2 might consist of several Oracle schemas :-).

Plus schema can also mean a bunch of other, fairly unrelated things in other contexts (e.g. in mathematics).

Oracle should just have used a term like "userarea" or "accountobjects", instead of overloadin "schema"...

嗫嚅 2024-07-28 02:18:40

来自 WikiAnswers

  • 模式是数据库对象的集合,包括表、视图、序列等逻辑结构、存储过程、同义词、索引、集群和数据库链接。
  • 用户拥有一个模式。
  • 用户和模式具有相同的名称。
  • CREATE USER 命令创建一个用户。 它还会自动为该用户创建一个架构。
  • CREATE SCHEMA 命令并不像它所暗示的那样创建“架构”,它只是允许您创建多个表和视图,并在单个事务中在您自己的架构中执行多个授权。
  • 出于所有意图和目的,您可以将用户视为模式,将模式视为用户。

此外,如果用户有权限的话,他们还可以访问自己架构之外的对象。

From WikiAnswers:

  • A schema is collection of database objects, including logical structures such as tables, views, sequences, stored procedures, synonyms, indexes, clusters, and database links.
  • A user owns a schema.
  • A user and a schema have the same name.
  • The CREATE USER command creates a user. It also automatically creates a schema for that user.
  • The CREATE SCHEMA command does not create a "schema" as it implies, it just allows you to create multiple tables and views and perform multiple grants in your own schema in a single transaction.
  • For all intents and purposes you can consider a user to be a schema and a schema to be a user.

Furthermore, a user can access objects in schemas other than their own, if they have permission to do so.

秋心╮凉 2024-07-28 02:18:40

像平常一样将用户(有权登录并访问系统中的某些对象的用户名/密码)和模式视为用户主目录的数据库版本。 用户“foo”通常在模式“foo”下创建事物,例如,如果用户“foo”创建或引用表“bar”,那么Oracle将假定该用户意味着“foo.bar”。

Think of a user as you normally do (username/password with access to log in and access some objects in the system) and a schema as the database version of a user's home directory. User "foo" generally creates things under schema "foo" for example, if user "foo" creates or refers to table "bar" then Oracle will assume that the user means "foo.bar".

比忠 2024-07-28 02:18:40

这个答案没有定义所有者和模式之间的区别,但我认为它增加了讨论。

在我的小思考世界中:

我一直在努力思考创建 N 个用户,我希望这些用户中的每一个“消费”(也称为使用)单个模式。

oracle-base.com 上的 Tim 展示了如何执行此操作 (有 N 个用户,每个用户都将被“重定向”到单个模式。

他有第二种“同义词”方法(此处未列出)。我在这里仅引用 CURRENT_SCHEMA 版本(他的方法之一):

CURRENT_SCHEMA 方法

此方法使用 CURRENT_SCHEMA 会话属性自动
将应用程序用户指向正确的架构。

首先,我们创建架构所有者和应用程序用户。

CONN 系统/密码 AS SYSDBA 

  -- 删除现有的同名用户和角色。 
  删除用户 schema_owner CASCADE; 
  删除用户 app_user 级联; 
  删除角色 schema_rw_role; 
  删除角色 schema_ro_role; 

  -- 模式所有者。 
  创建用户 schema_owner 由密码识别 
    默认表空间用户 
    临时表空间温度 
    用户配额无限; 

  授予连接,为 schema_owner 创建表; 

  ——应用程序用户。 
  创建用户 app_user 由密码识别 
    默认表空间用户 
    临时表空间温度; 

  授予连接到app_user; 
  

请注意,应用程序用户可以连接,但没有任何权限
表空间配额或创建对象的权限。

接下来,我们创建一些角色以允许读写和只读访问。

创建角色 schema_rw_role; 
  创建角色 schema_ro_role; 
  

我们希望为应用程序用户提供对架构的读写访问权限
对象,因此我们授予相关角色。

将 schema_rw_role 授予 app_user; 
  

我们需要确保应用程序用户拥有其默认架构
指向架构所有者,因此我们创建一个 AFTER LOGON 触发器来
为我们做这件事。

创建或替换触发器 app_user.after_logon_trg 
  登录 app_user.SCHEMA 后 
  开始 
    DBMS_APPLICATION_INFO.set_module(USER, '初始化'); 
    立即执行 'ALTER SESSION SET current_schema=SCHEMA_OWNER'; 
  结尾; 
  / 
  

现在我们准备在架构所有者中创建一个对象。

CONN schema_owner/密码 

  创建表 test_tab ( 
    身份证号码, 
    描述 VARCHAR2(50), 
    约束 test_tab_pk 主键(id) 
  ); 

  将 test_tab 上的选择授予 schema_ro_role; 
  将 test_tab 上的选择、插入、更新、删除授予 schema_rw_role; 
  

注意如何将权限授予相关角色。 没有
这样,应用程序用户将看不到这些对象。 我们现在
拥有正常运行的架构所有者和应用程序用户。

SQL>   CONN 应用程序_用户/密码 
  连接的。 
  SQL>   DESC 测试_选项卡 
   名字为空?   类型 
   -------------------------------------------------- --- -------- ------------------------------------ 
   ID 不为空号码 
   描述 VARCHAR2(50) 

  SQL> 
  

当应用程序用户只是一个简单的用户时,此方法是理想的选择。
主模式的替代入口点,不需要任何对象
它自己的。

This answer does not define the difference between an owner and schema but I think it adds to the discussion.

In my little world of thinking:

I have struggled with the idea that I create N number of users where I want each of these users to "consume" (aka, use) a single schema.

Tim at oracle-base.com shows how to do this (have N number of users and each of these users will be "redirected" to a single schema.

He has a second "synonym" approach (not listed here). I am only quoting the CURRENT_SCHEMA version (one of his approaches) here:

CURRENT_SCHEMA Approach

This method uses the CURRENT_SCHEMA session attribute to automatically
point application users to the correct schema.

First, we create the schema owner and an application user.

CONN sys/password AS SYSDBA

-- Remove existing users and roles with the same names.
DROP USER schema_owner CASCADE;
DROP USER app_user CASCADE;
DROP ROLE schema_rw_role;
DROP ROLE schema_ro_role;

-- Schema owner.
CREATE USER schema_owner IDENTIFIED BY password
  DEFAULT TABLESPACE users
  TEMPORARY TABLESPACE temp
  QUOTA UNLIMITED ON users;

GRANT CONNECT, CREATE TABLE TO schema_owner;

-- Application user.
CREATE USER app_user IDENTIFIED BY password
  DEFAULT TABLESPACE users
  TEMPORARY TABLESPACE temp;

GRANT CONNECT TO app_user;

Notice that the application user can connect, but does not have any
tablespace quotas or privileges to create objects.

Next, we create some roles to allow read-write and read-only access.

CREATE ROLE schema_rw_role;
CREATE ROLE schema_ro_role;

We want to give our application user read-write access to the schema
objects, so we grant the relevant role.

GRANT schema_rw_role TO app_user;

We need to make sure the application user has its default schema
pointing to the schema owner, so we create an AFTER LOGON trigger to
do this for us.

CREATE OR REPLACE TRIGGER app_user.after_logon_trg
AFTER LOGON ON app_user.SCHEMA
BEGIN
  DBMS_APPLICATION_INFO.set_module(USER, 'Initialized');
  EXECUTE IMMEDIATE 'ALTER SESSION SET current_schema=SCHEMA_OWNER';
END;
/

Now we are ready to create an object in the schema owner.

CONN schema_owner/password

CREATE TABLE test_tab (
  id          NUMBER,
  description VARCHAR2(50),
  CONSTRAINT test_tab_pk PRIMARY KEY (id)
);

GRANT SELECT ON test_tab TO schema_ro_role;
GRANT SELECT, INSERT, UPDATE, DELETE ON test_tab TO schema_rw_role;

Notice how the privileges are granted to the relevant roles. Without
this, the objects would not be visible to the application user. We now
have a functioning schema owner and application user.

SQL> CONN app_user/password
Connected.
SQL> DESC test_tab
 Name                                                  Null?    Type
 ----------------------------------------------------- -------- ------------------------------------
 ID                                                    NOT NULL NUMBER
 DESCRIPTION                                                    VARCHAR2(50)

SQL>

This method is ideal where the application user is simply an
alternative entry point to the main schema, requiring no objects of
its own.

战皆罪 2024-07-28 02:18:40

这很简单。

If USER has OBJECTS
then call it SCHEMA
else
     call it USER
end if;

用户可以被授予对不同用户拥有的模式对象的访问权。

It's very simple.

If USER has OBJECTS
then call it SCHEMA
else
     call it USER
end if;

A user may be given access to schema objects owned by different Users.

乖乖兔^ω^ 2024-07-28 02:18:40

模式是关于感兴趣的想法/领域的 DB.objects 的封装,并由一个用户拥有。 然后,它将由具有受抑制角色的其他用户/应用程序共享。 因此,用户不需要拥有模式,但模式需要有所有者。

Schema is an encapsulation of DB.objects about an idea/domain of intrest, and owned by ONE user. It then will be shared by other users/applications with suppressed roles. So users need not own a schema, but a schema needs to have an owner.

感性不性感 2024-07-28 02:18:40

--USER 和 SCHEMA

用户和模式这两个词是可以互换的,这就是为什么大多数人对这个词感到困惑,下面我解释了它们之间的区别

--User 用户是连接数据库(服务器)的帐户。 我们可以使用 CREATE USER user_name IDENTIFIED BY password 来创建用户。

--Schema

实际上Oracle数据库包含处理数据的逻辑和物理结构。Schema也是处理数据库(内存组件)中数据的逻辑结构。 它是在创建用户时由 oracle 自动创建的。它包含由与该模式关联的用户创建的所有对象。例如,如果我创建了一个名为 santhosh 的用户,那么 oracle 创建了一个名为 santhosh 的模式,oracle 将用户 santhosh 创建的所有对象存储在 santhosh 中架构。

我们可以通过 CREATE SCHEMA 语句创建模式,但是 Oracle 会自动为该模式创建用户。

我们可以使用 DROP SCHEMA scama_name RESTRICT 语句删除模式,但它不能删除包含对象的模式,因此要删除模式,它必须为空。这里的限制字强制指定不包含对象的模式。

如果我们尝试删除用户架构中的包含对象,我们必须指定 CASCADE 单词,因为 Oracle 不允许删除用户包含对象。
DROP USER 用户名 CASCADE
因此,oracle 删除模式中的对象,然后自动删除用户,从其他模式(如视图和私有同义词)引用此模式对象的对象将进入无效状态。

--USER and SCHEMA

The both words user and schema are interchangeble,thats why most people get confusion on this words below i explained the difference between them

--User User is a account to connect database(Server). we can create user by using CREATE USER user_name IDENTIFIED BY password .

--Schema

Actually Oracle Database contain logical and physical strucutre to process the data.The Schema Also Logical Structure to process the data in Database(Memory Component). Its Created automatically by oracle when user created.It Contains All Objects created by the user associated to that schema.For Example if i created a user with name santhosh then oracle createts a schema called santhosh,oracle stores all objects created by user santhosh in santhosh schema.

We can create schema by CREATE SCHEMA statement ,but Oracle Automatically create a user for that schema.

We can Drop the schema by using DROP SCHEMA schama_name RESTRICT statement but it can not delete scehema contains objects,so to drop schema it must be empty.here the restrict word forcely specify that schema with out objects.

If we try to drop a user contain objects in his schema we must specify CASCADE word because oracle does not allow you to delete user contain objects.
DROP USER user_name CASCADE
so oracle deletes the objects in schema and then it drops the user automatically,Objects refered to this schema objects from other schema like views and private synonyms goes to invalid state.

冰雪之触 2024-07-28 02:18:40

基于我对 Oracle 的一点了解......用户和架构有点相似。 但也有一个重大区别。 如果“用户”拥有任何对象,则用户可以称为模式,否则......它将仅保留为“用户”。 一旦用户拥有至少一个对象,那么根据上面的所有定义......用户现在可以称为模式。

Based on my little knowledge of Oracle... a USER and a SCHEMA are somewhat similar. But there is also a major difference. A USER can be called a SCHEMA if the "USER" owns any object, otherwise ... it will only remain a "USER". Once the USER owns at least one object then by virtue of all of your definitions above.... the USER can now be called a SCHEMA.

怀中猫帐中妖 2024-07-28 02:18:40

用户帐户就像持有您家钥匙的亲戚,但不拥有任何东西,即用户帐户不拥有任何数据库对象...没有数据字典...

而模式是数据库对象的封装。 这就像房子的主人拥有你房子里的所有东西,只有当主人(即模式)向它提供所需的补助时,用户帐户才能够访问家里的物品。

A user account is like relatives who holds a key to your home, but does not own anything i.e. a user account does not own any database object...no data dictionary...

Whereas a schema is an encapsulation of database objects. It's like the owner of the house who owns everything in your house and a user account will be able to access the goods at the home only when the owner i.e. schema gives needed grants to it.

ζ澈沫 2024-07-28 02:18:40

对于大多数更熟悉 MariaDB 或 MySQL 的人来说,这似乎不太令人困惑,因为在 MariaDB 或 MySQL 中,它们具有不同的模式(包括不同的表、视图、PLSQL 块和数据库对象等),而 USERS 是可以访问这些模式的帐户。架构。 因此,没有特定的用户可以属于任何特定的模式。 必须向该架构授予权限,然后用户才能访问它。 在 MySQL 和 MariaDB 等数据库中,用户和架构是分开的。

在 Oracle 中,模式和用户几乎被视为相同。 要使用该模式,您需要拥有权限,您会觉得模式名称只是用户名。 可以跨模式授予权限,以从不同模式访问不同的数据库对象。 在 Oracle 中,我们可以说用户拥有模式,因为当您创建用户时,您会为其创建数据库对象,反之亦然。

For most of the people who are more familiar with MariaDB or MySQL this seems little confusing because in MariaDB or MySQL they have different schemas (which includes different tables, view , PLSQL blocks and DB objects etc) and USERS are the accounts which can access those schema. Therefore no specific user can belong to any particular schema. The permission has be to given to that Schema then the user can access it. The Users and Schema is separated in databases like MySQL and MariaDB.

In Oracle schema and users are almost treated as same. To work with that schema you need to have the permission which is where you will feel that the schema name is nothing but user name. Permissions can be given across schemas to access different database objects from different schema. In oracle we can say that a user owns a schema because when you create a user you create DB objects for it and vice a versa.

白云不回头 2024-07-28 02:18:40

模式和数据库用户是相同的,但如果模式拥有数据库对象,并且他们可以执行其对象的任何操作,但用户只能访问对象,则在模式用户授予您适当的权限之前,他们无法执行任何 DDL 操作。

A schema and database users are same but if schema has owned database objects and they can do anything their object but user just access the objects, They can't DO any DDL operations until schema user give you the proper privileges.

蘸点软妹酱 2024-07-28 02:18:40

用户:对数据库资源的访问。 就像进入房子的钥匙一样。

模式:有关数据库对象的信息的集合。 就像书中的索引一样,其中包含有关该章节的简短信息。

查看此处了解详细信息

User: Access to resource of the database. Like a key to enter a house.

Schema: Collection of information about database objects. Like Index in your book which contains the short information about the chapter.

Look here for details

百善笑为先 2024-07-28 02:18:40

用户是连接数据库服务器的帐户。

我们可以使用以下方法创建用户:

创建用户用户名由密码识别。

模式是特定用户的所有对象的集合。 用户只是数据库中的一个帐户。 作为外行,您可以将银行视为数据库,将您在该银行的帐户视为用户,并将您帐户下可用的所有内容(您的储蓄帐户、储物柜等)视为您的架构。

另请阅读此

  • 内容 架构是数据库对象的集合,包括表、视图、序列、存储过程、同义词、索引、簇和数据库链接等逻辑结构。
  • 用户拥有一个模式。
  • 用户和模式具有相同的名称。
  • CREATE USER 命令创建一个用户。 它还会自动为该用户创建一个架构。
  • 出于所有意图和目的,您可以将用户视为模式,将模式视为用户。

User is a account to connect Database Server.

We can create user by using:

CREATE USER user_name IDENTIFIED BY password.

Schema is collection of all the objects for a particular user. User is just an account in the database . As a laymen you can think as Bank as a Database and Your account in that bank as User and all things available under your account (Ur saving account,Locker etc) as your schema.

Also read this

  • A schema is collection of database objects, including logical structures such as tables, views, sequences, stored procedures, synonyms, indexes, clusters, and database links.
  • A user owns a schema.
  • A user and a schema have the same name.
  • The CREATE USER command creates a user. It also automatically creates a schema for that user.
  • For all intents and purposes you can consider a user to be a schema and a schema to be a user.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文