Oracle User 和 Schema 的區別

lhrbest發表於2017-08-04

 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)。





About Me

.............................................................................................................................................

● 本文轉載:http://www.cndba.cn/dave/article/2046

● 本文在itpub(http://blog.itpub.net/26736162/abstract/1/)、部落格園(http://www.cnblogs.com/lhrbest)和個人微信公眾號(xiaomaimiaolhr)上有同步更新

● 本文itpub地址:http://blog.itpub.net/26736162/abstract/1/

● 本文部落格園地址:http://www.cnblogs.com/lhrbest

● 本文pdf版、個人簡介及小麥苗雲盤地址:http://blog.itpub.net/26736162/viewspace-1624453/

● 資料庫筆試面試題庫及解答:http://blog.itpub.net/26736162/viewspace-2134706/

● DBA寶典今日頭條號地址:http://www.toutiao.com/c/user/6401772890/#mid=1564638659405826

.............................................................................................................................................

● QQ群號:230161599(滿)、618766405

● 微信群:可加我微信,我拉大家進群,非誠勿擾

● 聯絡我請加QQ好友646634621,註明新增緣由

● 於 2017-08-01 09:00 ~ 2017-08-31 22:00 在魔都完成

● 文章內容來源於小麥苗的學習筆記,部分整理自網路,若有侵權或不當之處還請諒解

● 版權所有,歡迎分享本文,轉載請保留出處

.............................................................................................................................................

小麥苗的微店https://weidian.com/s/793741433?wfr=c&ifr=shopdetail

小麥苗出版的資料庫類叢書http://blog.itpub.net/26736162/viewspace-2142121/

.............................................................................................................................................

使用微信客戶端掃描下面的二維碼來關注小麥苗的微信公眾號(xiaomaimiaolhr)及QQ群(DBA寶典),學習最實用的資料庫技術。

   小麥苗的微信公眾號      小麥苗的DBA寶典QQ群1     小麥苗的DBA寶典QQ群2        小麥苗的微店

.............................................................................................................................................

Oracle User 和 Schema 的區別
DBA筆試面試講解群1
DBA筆試面試講解群2
歡迎與我聯絡



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26736162/viewspace-2143101/,如需轉載,請註明出處,否則將追究法律責任。

相關文章