当前位置:网站首页>Oracle advanced (V) schema solution

Oracle advanced (V) schema solution

2022-07-07 13:34:00 InfoQ

One 、 Definition

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.

We can see from the definition
schema
Is a collection of database objects , In order to distinguish the various sets , We need to give this collection a name , These names are the many user name like nodes we see in the enterprise manager solution , These user name like nodes are actually a
schema
,
schema
It contains all kinds of objects, such as
tables, views, sequences, stored procedures, synonyms, indexes, clusters, and database links
.

One user corresponds to one
schema
, The user's
schema
Name equals user name , And as the user's default
schema
. This is what we see in the enterprise manager solution
schema
The reason why the names are all database user names .

Oracle
You can't create a new one in the database
schema
, To create a
schema
, It can only be solved by creating one user (Oracle Although there are
create schema
sentence , But it's not meant to create a
schema
Of ), Create a user with the same name as the user name at the same time
schem
, And as the user's default
shcema
. namely
schema
The number of is the same as user The same number of , and
schema
Same name
user
The names are one-to-one and the same , All we can call
schema
by user Another name for , Although that's not accurate , But it's easier to understand .

A user has a default
schema
, Its schema Name equals user name , Of course, a user can use other schema. If we visit a table , It does not indicate which
schema
Medium , The system will automatically add the default
sheman
name . For example, when we access a database , visit scott Under the user emp surface , adopt
select * from emp;
  Actually , this sql The sentence is written in a complete way
select * from scott.emp
. The full name of an object in the database is
schema.object
, It's not user.object. Similarly, if we don't specify the schema, In the
schema
For the user's default
schema
. It's like a user has a default table space , But the user can also use other table spaces , If we don't specify a table space when we create an object , The object is stored in the default table space , To store objects in other table spaces , We need to specify the table space of the object when we create it .

Two 、 give an example

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; -- Change the user default schema name
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 TESTSYSTEM TEST

The above query is what I said will
schema
As user Basis of alias of . Actually in use ,shcema And user Exactly the same as , There's no difference , In the presence of schema Places with names can also appear user name .
原网站

版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071055162858.html