ORACLESQL database objects

ORACLESQL database objects


开发工具与关键技术:Oracle sql*plus PLSQL Developer

作者:黄元进

撰写时间:2019年03月26日

Common database objects

Table ---> basic data set storage, the rows and columns

View -> set of logically related data extracted from the table

Sequence -> provides a regular value

Index -> improve the efficiency of query

Synonyms -> to the object from the alias

What is the sequence?

Sequence: for a plurality of users to generate a unique value of database objects

• automatically provide unique value

• shared objects

• mainly used to provide primary key values

• The sequence value into memory access efficiency can be improved

Creating a Sequence

• Create a sequence DEPT_DEPTID_SEQ provide the primary key for the table DEPARTMENTS

• Do not use the CYCLE option
Here Insert Picture Description

Query sequence

• Query the data dictionary view USER_SEQUENCES obtain sequence information is defined

• Show next sequence If you specify a valid value NOCACHE option, the column LAST_NUMBER
Here Insert Picture Description

And dummy column NEXTVAL CURRVAL

• NEXTVAL returns the next available sequence value, any user can reference

• The current value is stored in the sequence of CURRVAL

• NEXTVAL should be specified before CURRVAL, otherwise it will report an error CURRVAL not yet defined in this session.

Sequence Application examples
Here Insert Picture Description

Use sequence

• The sequence values ​​into memory access efficiency can be improved

• cracks sequence occurs in the following cases:

- Rollback

- system abnormalities

- a plurality of tables simultaneously use the same sequence

• If you do not value loaded into memory sequence (NOCACHE), can be used to view the table USER_SEQUENCES sequence current rms

Modifying sequence: sequence of incremental changes, maximum, minimum, cycle option, or whether it is loaded into memory

Notes modify the sequence

• sequence must be the owner or have ALTER permission on the sequence

• Only future sequence values ​​will be changed

• change the initial value of the sequence can only be achieved by a process of rebuilding a sequence after sequence deleted
Here Insert Picture Description
deleted sequence

• DROP SEQUENCE statement to remove the use of sequence

• After deletion, the sequence can not be referenced again
Here Insert Picture Description
indexed

• an independent schema objects in the table, the table can be stored in different disk space or table

• The index is deleted or damaged, will not have an impact on the table, its impact is only on the speed

• Index Once established, Oracle management system will be maintained automatically, and decide when to use Oracle Management index. Users do not have to specify which index to use in the query

• When you delete a table, all will be automatically deleted based index of the table

• accelerate query speed Oracle server through a pointer

• The method is rapid positioning data, reduce disk I / 0

Creating an index

• Automatic creation: the system automatically creates a unique index on the corresponding column After defining PRIMARY KEY or UNIQUE constraint

• manually create: Users can create nonunique indexes on other columns to speed up queries

• Create an index on one or more columns
Here Insert Picture Description

• Create an index on LAST_NAME column of the table EMPLOYEES
Here Insert Picture Description

When creating an index

• Column distributed in a wide range of data values

• columns often appear in the WHERE clause or join condition

• frequently accessed tables and a large amount of data, access data about 2% to 4% of the total amount of data

When not creating an index

• table is small

• column does not often appear as the connection conditions or in the WHERE clause

• data query more than 2% to 4%

• table is updated frequently

Query Index

• Information can use the data dictionary views USER_INDEXES and USER_IND_COLUMNS View index
Here Insert Picture Description

Delete Index

• Use DROP INDEX command to delete index
Here Insert Picture Description
• remove the index UPPER_LAST_NAME_IDX
Here Insert Picture Description
Note:

• Only the owner or user of the index have DROP ANY INDEX privileges can delete the index

• delete operation can not be rolled back

Synonyms -synonym

Use the same object synonymous with defense

• Objects easy access to other users

• shorten the length of the object name
Here Insert Picture Description

Create and delete synonyms

• Create a synonym for the view DEPT_SUM_VU
Here Insert Picture Description
• Delete Synonym
Here Insert Picture Description

Guess you like

Origin blog.csdn.net/weixin_44547949/article/details/89058964