oracle中schema指的是什么?

一、Oracle schema 概念

Users not only access data in a database, but they own the objects thatsql

contain the data. The set of objects owned by a user is its schema. 拥有一个Oracle数据库对象的用户,就有schema。数据库

Not all users own objects so schemas may be empty.session

Other users can access or execute objects within a user’s schema once theapp

schema owner grants privileges. ide

It is common practice to have one user own all of an application’s objects (tables, indexes, views, and so on) and then provide access to those objects to all the application users within the database.this

This is done via database grants, roles, and synonyms.spa

For example, assume you have the ACME application. You’d create a user called.net

ACME_OWN and create all objects as ACME_OWN. Then you’d create a databasecode

role called ACME_USER and grant SELECT, UPDATE, EXECUTE for the objects对象

in ACME_OWN’s schema to that role. Application users would be granted the

ACME_USER role so they could access the ACME_OWN’s objects. This way one

user owns the objects, but the actual database or application users access the

data. This separation improves both security and manageability.

《Oracle 11g for dummies》 p136

下面内容摘自 csdn 博文 http://blog.csdn.net/KimSoft/article/details/4627520

看来有的人仍是对schema的真正含义不太理解,如今我再次整理了一下,但愿对你们有所帮助。

咱们先来看一下他们的定义:
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.
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。

一个用户通常对应一个schema,该用户的schema名等于用户名,并做为该用户缺省schema。这也就是咱们在企业管理器的方案下看到schema名都为数据库用户名的缘由。Oracle数据库中不能新建立一个schema,要想建立一个schema,只能经过建立一个用户的方法解决(Oracle中虽然有create schema语句,可是它并非用来建立一个schema的),在建立一个用户的同时为这个用户建立一个与用户名同名的schem并做为该用户的缺省shcema。即schema的个数同user的个数相同,并且schema名字同user名字一一 对应而且相同,全部咱们能够称schema为user的别名,虽然这样说并不许确,可是更容易理解一些。

一个用户有一个缺省的schema,其schema名就等于用户名,固然一个用户还可使用其余的schema。若是咱们访问一个表时,没有指明该表属于哪个schema中的,系统就会自动给咱们在表上加上缺省的sheman名。好比咱们在访问数据库时,访问scott用户下的emp表,经过select * from emp; 其实,这sql语句的完整写法为select * from scott.emp。在数据库中一个对象的完整名称为schema.object,而不属user.object。相似若是咱们在建立对象时不指定该对象的schema,在该对象的schema为用户的缺省schema。这就像一个用户有一个缺省的表空间,可是该用户还可使用其余的表空间,若是咱们在建立对象时不指定表空间,则对象存储在缺省表空间中,要想让对象存储在其余表空间中,咱们须要在建立对象时指定该对象的表空间。

咳,说了这么多,给你们举个例子,不然,一切枯燥无味!
SQL> Gruant dba to scott

SQL> create table test(name char(10));
Table created.

SQL> create table system.test(name char(10));
Table created.

SQL> insert into test values('scott'); 
1 row created.

SQL> insert into system.test values('system');
1 row created.

SQL> commit;
Commit complete.

SQL> conn system/manager
Connected.

SQL> select * from test;
NAME
----------
system

SQL> ALTER SESSION SET CURRENT_SCHEMA = scott; --改变用户缺省schema名
Session altered.

SQL> select * from test;
NAME
----------
scott

SQL> select owner ,table_name from dba_tables where table_name=upper('test');
OWNER TABLE_NAME
------------------------------ ------------------------------
SCOTT TEST
SYSTEM TEST
--上面这个查询就是我说将schema做为user的别名的依据。实际上在使用上,shcema与user彻底同样,没有什么区别,在出现schema名的地方也能够出现user名。


1.1 Oracle 建立用户

CREATE USER <USERNAME>
IDENTIFIED BY “<PASSWORD>” ###密码用“”
TEMPORARY TABLESPACE <TEMPORARY TABLESPACE>
DEFAULT TABLESPACE <DEFAULT TABLSPAC>;


In the following steps you create a user with SQL*Plus and grant the necessary

roles and privileges to connect to the database:

1. In SQL*Plus, type the following to create a user:

SYS@dev11g> create user acme_own
2 identified by “acme_own2008!!”
3 temporary tablespace temp
4 default tablespace users;

User created.

In this example, the user is schema owner ACME_OWN. The default

tablespace is defined as USERS, although the TABLESPACE storage

clause is expected to specify ACME_DATA when objects are created


2. Grant the user CONNECT and RESOURCE roles so that the user can log

in to the database and create objects:

SYS@dev11g> grant connect to acme_own;
Grant succeeded.
SYS@dev11g> grant resource to acme_own;

Grant succeeded.

3. Create a new role:

SYS@dev11g> create role acme_user;
Role created.
SYS@dev11g> grant create session to acme_user;

Grant succeeded.

相关文章
相关标签/搜索