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!