Schema (Schema in the database)

The schema in the database is a collection of database objects, and a user generally corresponds to a schema.
 
Chinese name
Overview
foreign name
schema
Correspondence
A user generally corresponds to a schema
The official definition is as follows:
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.
From the definition, we can see that schema is a collection of database objects. In order to distinguish each collection, we need to give this collection a name. These names are the many nodes that are similar to user names that we see under the scheme of Enterprise Manager. These A node similar to a username is actually a schema, which contains various objects such as tables views sequences stored procedures synonyms indexes clusters and database links.
A user generally corresponds to a schema. The user's schema name is equal to the user name, and is used as the user's default schema. This is why we see that the schema names are all database usernames under the Enterprise Manager scheme. A new schema cannot be created in the oracle database. To create a schema, it can only be solved by creating a user (although there is a create schema statement in oracle, it is not used to create a schema). When creating a user At the same time, a schema with the same name as the user name is created for this user and used as the default schema for the user. That is, the number of schemas is the same as the number of users, and the schema name corresponds to the user name one-to-one and is the same, so we can call the schema an alias of the user, although it is not accurate, but it is easier to understand.
A user has a default schema, and its schema name is equal to the user name. Of course, a user can also use other schemas. If we access a table without specifying which schema the table belongs to, the system will automatically add the default sheman name to the table for us. For example, when we access the database, we access the emp table under the scott user through select from emp. In fact, the complete writing of this sql statement is select from scott.emp. The full name of an object in the database is schema.object, not user.object. Similarly, if we do not specify the schema of the object when we create the object, the schema of the object is the default schema of the user. This is like a user has a default tablespace , but the user can also use other tablespaces. If we do not specify a tablespace when creating an object, the object is stored in the default tablespace. To make the object store In other tablespaces, we need to specify the object's tablespace when creating the object.
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 -- change the user's 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 test
system test
--The above query is the basis for me to use schema as the alias of user. In fact, in use, schema and user are exactly the same, there is no difference, and the user name can also appear where the schema name appears.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326093238&siteId=291194637