2011年3月29日 星期二

Oracle 的 Schema 與 User 的關係

Oracle 真的與 SQL Server 大不同啊!

在 SQL Server 來說,Schema 只是一群 table, view, stored procedure 等的容器。一個 schema 可以給予不同 user 不同的權限。因此,schema 與 user 的關係並不是一對一的。

而在 Oracle,Schema 幾乎就等同於 User。當建立一個 User 時,就會自動建立出對應的 schema。預設的狀況下,不同的 user 因此就看不到其他user 的資料,因為是在不同的 schema 下。當然,經過授權後,其他 user 就可以讀取了。

例子

在 SQL Server 中,我們可以單純建立一個 Accounting 的 schema,再授權給已經存在的 user “Charles”。

在 Oracle 中,為了建立一個 Accounting 這個 schema,我們必須建立一個 user 名為 Accounting,才能得到這個 Accounting 這個 schema。然而,Accounting 這個 user 並不是我們想要的,只好將 Accounting 這個 user 給鎖定。

參考

http://wiki.answers.com/Q/Difference_between_user_and_schema_oracle ,寫到下面的重點

Difference between user and schema oracle?

* A schema is collection of database objects, including logical structures such as tables, views, sequences, stored procedures, synonyms, indexes, clusters, and database links.
* A user owns a schema.
* A user and a schema have the same name.
* The CREATE USER command creates a user. It also automatically creates a schema for that user.
* The CREATE SCHEMA command does not create a "schema" as it implies, it just allows you to create multiple tables and views and perform multiple grants in your own schema in a single transaction.
* For all intents and purposes you can consider a user to be a schema and a schema to be a user.

沒有留言:

Share with Facebook