Oracle User、Schema、Default Tablespace

来源:互联网 发布:mac终端退出当前命令 编辑:程序博客网 时间:2024/06/05 07:41


User和Schema并不是同一个东西,人们很容易把这两个概念混淆:
  • Oracle User :Oracle数据库的账户。
  • Oracle Schema: Oracle User + Oracle User所拥有的数据库对象集合。
ASKTOM:Link
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.


当使用CREATE USER创建用户的时候,数据库会自动创建一个同名Schema,如SCOTT用户的Schema也叫SCOTT。

User和Schema总是1-1对应的,大多数情况下User的名称和Schema的名称是一致的,但是在有些情况下是不同的。

一个挺形象的比喻:schema如房子,user如房子的主人
user即Oracle中的用户,和所有系统的中用户概念类似,用户所持有的是系统的权限及资源;而schema所涵盖的是各种对象,它包含了表、函数、包等等对象的“所在地”,并不包括对他们的权限控制。好比一个房子,里面放满了家具,对这些家具有支配权的是房子的主人(user),而不是房子(schema)。你可以也是一个房子的主人(user),拥有自己的房子(schema)。

可以通过alter session的方式进入别人的房子。这个时候,你可以看到别人房子里的家具(desc)。如果你没有特别指定的话,你所做的操作都是针对你当前所在房子中的东西。至于你是否有权限使用(select)、搬动(update)或者拿走(delete)这些家具就看这个房子的主人有没有给你这样的权限了,或者你是整个大厦(DB)的老大(DBA)。alter session set schema可以用来代替synonyms。

如果你想调用其他schema的对象(有权限的前提下),但并没有建synonym,同时又不想把其他schema名字放入代码中,就可以首先使用alter session set schema=<其他schema名字>。 

用户和缺省表空间:
10g以前,系统缺省表空间为SYSTEM表空间,这样的设置并不合理,操作不当可能造成SYSTEM表空间非常庞大。针对用户习惯,Oracle 10g中定义了数据库级别的默认表空间USERS,在创建用户时没有定义默认表空间,就会把数据库级别的默认表空间当作自己的默认表空间。
SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE    11.2.0.1.0      Production
TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production


--系统默认表空间查询
SQL> SELECT PROPERTY_VALUE
  2    FROM database_properties
  3   WHERE PROPERTY_NAME = 'DEFAULT_PERMANENT_TABLESPACE' ;

PROPERTY_VALUE
---------------------------------------------------------------
USERS

--不指定表空间的情况下,用户默认表空间为USER表空间。
SQL> create user tianpan identified by welcome;

User created.
SQL> select username,default_tablespace,temporary_tablespace
  2  from dba_users
  3  where username = 'TIANPAN';

USERNAME                       DEFAULT_TABLESPACE             TEMPORARY_TABLESPACE
------------------------------ ------------------------------ ------------------------------
TIANPAN                        USERS                          TEMP

--建议在创建用户时就为用户指定缺省的表空间,而不是依赖系统的缺省设置。
create user tianpan identified by welcome
default tablespace users
temporary tablespace temp;


参考
The Difference between User and Schema in Oracle
Thanks for the question regarding "What is the meaning of schema?", version 8.1.7
两个不容易理解的概念──user和schema
 





0 0