oracle schema和mysql_Oracle User 和 Schema 的区别

1概述

Schema和User的定义如下

A schema is a collection of database objects (used by a user.). Schema objects are the logical structures that directly refer to the database’s data.

A user is a name defined in the database that can connect to and access objects. Schemas and users help database administrators manage database security.

从定义中我们可以看出模式(Schema)为数据库对象的集合,为了区分各个集合,我们需要给这个集合起个名字,这些名字就是我们在企业管理器的方案下看到的许多类似用户名的节点,这些类似用户名的节点其实就是一个schema,schema里面包含了各种对象如tables, views, sequences, stored procedures, synonyms, indexes, clusters, and database links。

Oracle中虽然有create schema语句,但是它并不是用来创建一个schema的,具体见下面官方文档。

Use the CREATE SCHEMA statement to create multiple tables and views and perform multiple grants in your own schema in a single transaction. To execute a CREATE SCHEMA statement, Oracle Database executes each included statement. If all statements execute successfully, then the database commits the transaction. If any statement results in an error, then the database rolls back all the statements.

Note:This statement does not actually create a schema. Oracle Database automatically creates a schema when you create a user (see CREATE USER).

一个用户对应一个schema, 该用户的schema名等于用户名,并作为该用户缺省schema。这也就是我们在企业管理器的方案下看到schema名都为数据库用户名的原因。Oracle数据库中不能新创建一个schema,要想创建一个schema,只能通过创建一个用户的方法解决。

如果我们访问一个表时,没有指明该表属于哪一个schema中的,系统就会自动给我们在表上加上缺省的sheman名。比如我们在访问数据库时,访问scott用户下的emp表,通过

select * from emp;

其实,这sql语句的完整写法为

select * from scott.emp

在数据库中

一个对象的完整名称为schema.object,而不属user.object。类似如果我们在创建对象时不指定该对象的schema,在该对象的schema为用户的缺省schema。

2深入理解user和schema的区别

不同的schema之间它们没有直接的关系,不同的shcema之间的表可以同名,也可以互相引用(但必须有权限),在没有操作别的schema的操作根权下, 每个用户只能操作它自己的schema下的所有的表。不同的schema下的同名的表, 可以存入不同的数据(即schema用户自己的数据)。

好比一个房子,里面放满了家具,对这些家具有支配权的是房子的主人(user),而不是房子(schema)。

你可以也是一个房子的主人(user),拥有自己的房子(schema)。可以通过alter session的方式进入别人的房子。 这个时候,你可以看到别人房子里的家具(desc)。 如果你没有特别指定的话,你所做的操作都是针对你当前所在房子中的东西。

至于你是否有权限使用(select)、搬动(update)或者拿走(delete)这些家具就看这个房子的主人有没有给你这样的权限了,或者你是整个大厦(DB)的老大(DBA)。

整理自网络

https://www.cndba.cn/dave/article/2046

https://www.cndba.cn/dave/article/2046

https://www.cndba.cn/dave/article/2046

https://www.cndba.cn/dave/article/2046

https://www.cndba.cn/dave/article/2046

https://www.cndba.cn/dave/article/2046

https://www.cndba.cn/dave/article/2046

https://www.cndba.cn/dave/article/2046

https://www.cndba.cn/dave/article/2046

https://www.cndba.cn/dave/article/2046

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值