From Oracle constraints to Indexes

Source: Internet
Author: User

Oracle has five constraints. Primary key primary keys constraints, foreign key foreign constraints. Unique constraint, not null constraint, and check constraint. Remember: constraints are for a column.

Check constraints: alter table temp add constraint ck_temp_age CHECK

(AGE> 0) AND (AGE <= 125); in this way, age can only belong to the range from 0 to 125. Other data cannot be inserted.

Next, let's explain the differences between the primary keys constraint and the Unique constraint:

The primary keys constraint must be greater than the Unique constraint, that is, the Unique constraint is available, and the primary keys constraint is available. In addition, the primary keys constraint requires that the field cannot be null. The primary keys constraint automatically adds a unique index to the field.

A unique index is a type of index.

Oracle index types: There are three classification methods:

First: by type: 1. B-tree index 2. Bitmap Index

Type 2: 1. Unique index 2. Primary keyword index 3. General Index (mainly used to increase the query speed)

Category 3: 1. Single Column index 2. Multi-column index 3. Function Index

Create index I _ename on emp (ename); then a general index is created.

Create bitmap index index_name ON normal_index_creation_clause; a bitmap index is created.

Create unique index dept_unique_idx on dept (dept_no) tablespace idx_1; then create a unique index

Create constraints-related indexes. You can use the using index statement to create indexes related to the unique and primary key constraints. For example:

Alter table table_name

Add constraint PK_primary_keyname primary key (field_name)

Using index tablespace tablespace_name;

The last one used a lot to create constraints-related indexes.

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.