Differences between unique constraints and unique indexes in Oracle databases

Source: Internet
Author: User

OracleDatabaseUnique ConstraintAndUnique IndexThe difference is what we will introduce in this article. When using TOAD to operate Oracle databases, we will notice four types of constraints when creating constraints: Primary Key, Check, Unique, and Foreign Key, this is no different from the constraints in SQL Server. Besides the general Check constraints, the Check constraints are also used in Oracle for non-empty constraints. That is to say, if a field cannot be blank, the system will create a system Check constraint, which determines that a field cannot be blank.

In addition to constraints, another concept is indexing. The interface for creating an index in TOAD is as follows:

We can note that the uniqueness group has three options: not unique, unique, and primary key. What are the differences between the unique and primary key constraints when creating an index and the unique and primary key constraints when creating an index?

There may be misunderstandings here. In fact, the results of creating a primary key are the same. No matter when creating a constraint or creating an index, a primary key constraint and a unique index are created.

Creating a unique constraint is different from creating a unique index:

Creating a unique Constraint creates a Constraint in Oracle and a unique index corresponding to the Constraint.

Creating a unique index will only create one unique index and will not create a Constraint.

That is to say, the only constraint is implemented by creating a unique index. What is the difference between the two for front-end developers? It seems no. Duplicate values cannot be inserted. There are also some differences between the two. When deleting a unique constraint, you can only delete the constraint without deleting the corresponding index. Therefore, the column must be unique, if a unique index is deleted, an ununique value can be inserted.

The difference between the unique constraint and the unique index of the Oracle database is introduced here. I hope this introduction will be helpful to you!

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.