What is schema in Oracle?

Source: Internet
Author: User

It seems that some people still do not understand the true meaning of Schema. Now I have sorted it out again, hoping to help you.

Let's take a look at their definition:
ASchemaIs a collection of database objects (used by a user .).
Schema objectsAre the logical structures that directly refer to the database's data.
AUserIs a name defined in the database that can connect to and access objects.
Schemas and usersHelp database administrators manage database security.

From the definition, we can see that schema is a set of database objects. To distinguish each set, we need to name this set, these names are the nodes similar to user names that we see in the Enterprise Manager Solution. These nodes similar to user names are 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 schema name of the user is the same as the user name and serves as the user's default schema. This is why the schema names are database usernames in the Enterprise Manager Solution. You cannot create a new schema in an Oracle database. To create a schema, you can only create one user, but it is not used to create a schema). When creating a user, create a Schem with the same name as the user name and use it as the default shcema for the user. That is to say, the number of schemas is the same as the number of users, and the schema names are one-to-one and the same as the names of users. All aliases that can be called schema as users are inaccurate, but it is easier to understand.

A user has a default schema, and Its Schema name is the same as 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 example, when we access the database, we can access the EMP table under the Scott user through select * from EMP; in fact, the complete Syntax 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 creating the object, the schema of the object is the default schema of the user. This is like a user has a default tablespace, but this 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 store objects in other tablespaces, We need to specify the tablespace of the object when creating the object.

Ke, I have said so much. I will give you an example. Otherwise, everything will be boring!
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 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 using schema as the alias of the user. In fact, shcema is exactly the same as the user, and there is no difference. The user name can also appear in the place where the schema name appears.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.