Oracle's Uniqueness Constraint (UniqueConstraint) usage detailed ____oracle

Source: Internet
Author: User
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:?
1 2

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.