1 Goals
Demonstrates how to create, delete, disable, and use a uniqueness constraint with an example. 2 What is a uniqueness constraint.
A uniqueness constraint refers to a constraint in a table in which a field or multiple fields combine to uniquely identify a record. Union field, you can include null values.
Note: In Oracle, uniqueness constraints can have up to 32 columns.
Uniqueness constraints can be created when a table is created or by using the ALTER TABLE statement. 3 Uniqueness Constraint and primary key difference
Primary KEY (Primary key): All columns that make up a primary key cannot contain null values. Uniqueness constraint (unique Constraint): If a uniqueness constraint consists of multiple columns, some of the columns can contain null values. It is not allowed in Oracle to create both a primary key and a uniqueness constraint on the same column.
4 Defining uniqueness constraints when creating a table 1) Syntax:
?
| 1 2 3 4 5 6 7 |
CREATE TABLE table_name (COLUMN1 datatype null/not null, COLUMN2 datatype null/not null, ...) CONSTRAINT constraint_name UNIQUE (column1, Column2,..., column_n)); |
2 A single column based uniqueness constraint example:?
| 1 2 3 4 5 6 7 |
CREATE TABLE Tb_supplier (supplier_id number not NULL, Supplier_name varchar2), Contact_Name VARCHAR2, CONSTRAINT tb_supplier_u1 Unique (supplier_id)-Creates a uniqueness constraint when creating a table; |
3 Examples of uniqueness constraints based on multiple columns:?