百度文庫中 Schema 的解釋:
數據庫中的Schema,爲
數據庫對象的集合,一個用戶通常對應一個schema。
官方定義以下:
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。
一個用戶通常對應一個schema 該用戶的schema名等於用戶名,並做爲該用戶缺省schema。這也就是咱們在
企業管理器的方案下看到schema名都爲數據庫用戶名的緣由。oracle數據庫中不能新建立一個schema,要想建立一個schema,只能經過建立一個用戶的方法解決(oracle中雖然有create schema語句,可是它並非用來建立一個schema的),在建立一個用戶的同時爲這個用戶建立一個與用戶名同名的schema並做爲該用戶的缺省schema。即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> grant 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名。