oracle中schema指的是什么

如题所述

官方文档中关于schema是这样解释的:
  “A schema is a collection of database objects. A schema is owned by a database user and has the same name as that user. Schema objects are the logical structures that directly refer to the database's data. Schema objects include structures like tables, views, and indexes.(There is no relationship between a tablespace and a schema. Objects in the same schema can be in different tablespaces, and a tablespace can hold objects from different schemas.)”
  官方文档里面说得比较明白,schema是数据对象的集合,包括像表、视图、索引、同义词等等都可以说是schema的对象。
下面通过具体的例子来加深对user和schema两者区别的认识:
  第一步,以sys用户登陆SQL并建立普通用户storm和penguin:
  $ sqlplus / as sysdba
  SQL> create user storm identified by storm;
  User created.
  SQL> create user penguin identified by penguin;
  User created.
  第二步,赋予一些基本的权限给新建的用户storm和penguin:
  SQL> grant connect,create table,resource to storm,penguin;
  Grant succeeded.
  第三步,以storm用户登陆,创建一张表并插入数据:
  SQL> conn storm/storm
  Connected.
  SQL> create table t (id int);
  Table created.
  SQL> insert into t values(1);
  1 row created.
  SQL> commit;
  Commit complete.
  第四步,以penguin用户登陆,看能否查询storm用户所建表里面的数据:
  SQL> conn penguin/penguin
  Connected.
  SQL> select table_name from user_tables;
  no rows selected
  SQL> show user;
  USER is "PENGUIN"
  SQL> select * from storm.t;
  select * from storm.t
  *
  ERROR at line 1:
  ORA-00942: table or view does not exist
  从以上结果可以看出,用户 penguin无法查看用户storm所建表里面的内容,甚至被告知没有这张表。
  第五步,修改当前schema为storm,并继续查询:
  SQL> alter session set current_schema=storm;
  Session altered.
  SQL> show user;
  USER is "PENGUIN"
  SQL> select * from storm.t;
  select * from storm.t
  *
  ERROR at line 1:
  ORA-00942: table or view does not exist
  仍然不能查看。
  第六步,以storm用户登陆,赋予penguin用户查看t表的权限:
  SQL> conn storm/storm
  Connected.
  SQL> grant select on t to penguin;
  Grant succeeded.
  第七步,以penguin用户登陆,查看storm用户的t表:
  SQL> conn penguin/penguin
  Connected.
  SQL> select * from storm.t;
  ID
  ----------
  1
  更简单的,将当前schema更改为storm,可以简化查询过程:
  SQL> alter session set current_schema=storm;
  Session altered.
  SQL> select * from t;
  ID
  ----------
  1
温馨提示:答案为网友推荐,仅供参考
相似回答