Uniqueness of index names in Oracle

Source: Internet
Author: User

Database index processing is a bit of a problem, simply record

Oracle rules that objects under the same schema cannot be named with the same name, typically creating index names with "table name _ Field name", so that you can quickly know which table this index belongs to.

Col_index are called objects in Oracle and cannot be named the same

Cases:

  1. sql> Create table Emp1 as select * from scott.emp;
  2. Table created
  3. sql> Create table emp2 as select * from scott.emp;
  4. Table created
  5. sql> Create index emp1_name_idx on emp1 (ename);
  6. Index created
  7. sql> Create index emp1_name_idx on emp2 (ename);
  8. Create index emp1_name_idx on emp2 (ename)
  9. ORA-00955: Name already used by existing object

Reproduced under the schema of the analysis, from http://blog.csdn.net/kimsoft/article/details/4627520

let's start by looking at their definition:
a schema is a collection of the database objects (used by A user.).
Schema Objects is the logical structures that directly refer to the database ' s data.
a user is a name, defined in the database, can connect to and Access objects.
Schemas and users Help database administrators manage database security.

from the definition we can see that the schema is a collection of database objects, in order to distinguish between the collection, we need to give this collection a name, these are the many similar user names that we see under the Enterprise Manager Scheme node, these are similar to the user name of the node is actually a schema, The schema contains various objects such as tables, views, sequences, stored procedures, synonyms, indexes, clusters, and database links.

a user typically corresponds to a schema, the user's schema name equals the user name, and is used as the default schema for that user. This is why we see the schema name as the database username under the Enterprise Manager scenario. The Oracle database cannot create a new schema, and to create a schema, it can only be solved by creating a user's method (although Oracle has the CREATE SCHEMA statement, it is not used to create a schema) Create a user with a schem that has the same name as the user name and act as the default shcema for that user. That is, the number of schemas is the same as the number of user, and the schema name corresponds to the user name one by one and the same, all we can call the schema as the user alias, although this is not accurate, but it is easier to understand some.

A user has a default schema, whose schema name is equal to the user name, and of course a user can use other schemas. If we visit a table and do not indicate which schema the table belongs to, the system automatically adds the default Sheman name to the table. For example, when we access the database, we access the EMP table under the Scott user, through the select * from EMP; In fact, the complete syntax for this SQL statement is select * from Scott.emp. The full name of an object in the database is Schema.object, not user.object. Similar if we do not specify the schema of the object when creating the object, the schema of the object is the user's default schema. This is like a user with a default tablespace, but the user can also use other tablespaces, and if we do not specify a tablespace when we create the object, the object is stored in the default tablespace, and in order for the object to be stored in another table space, we need to specify the table space for the object when it is created.

cough, say so much, give everybody an example, otherwise, everything is dull!
sql> gruant dba to Scott

sql> CREATE TABLE Test (name char);
Table created.

sql> CREATE TABLE system.test (name char);
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 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 TEST
SYSTEM TEST
-The above query is the basis for me to say that the schema is the alias of the user. In fact, in use, Shcema is exactly the same as the user, there is no difference, the user name can appear where the schema name appears.

Uniqueness of index names in Oracle

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.