Code has been added to clipboard!

How to Use SQL UNIQUE in Oracle

Reading time 1 min
Published Aug 9, 2017
Updated Oct 3, 2019

SQL UNIQUE Constraint: Main Tips

  • You can use this constraint to classify each data cell in a table of a specific database in Oracle.
  • It is described in a PRIMARY KEY by default.
  • There can be only one PRIMARY KEY and a lot of UNIQUE constraints per table.
  • The SQL SELECT UNIQUE construct only works in Oracle. For other management systems, use SQL SELECT DISTINCT.
Udacity
Pros
  • Simplistic design (no unnecessary information)
  • High-quality courses (even the free ones)
  • Variety of features
Main Features
  • Nanodegree programs
  • Suitable for enterprises
  • Paid certificates of completion
Coursera
Pros
  • Professional service
  • Flexible timetables
  • A variety of features to choose from
Main Features
  • Professional certificates of completion
  • University-level courses
  • Multiple Online degree programs
Datacamp
Pros
  • Great user experience
  • Offers quality content
  • Very transparent with their pricing
Main Features
  • Free certificates of completion
  • Focused on data science skills
  • Flexible learning timetable

SQL UNIQUE Syntax Needed to CREATE TABLE

In the example below, we produce the UNIQUE constraint while creating the table:

Example
CREATE TABLE People (
    ID int NOT NULL UNIQUE,
    NameLast varchar(255) NOT NULL,
    NameFirst varchar(255),
    Year int
);

The code example below permits naming the constraints:

Example
CREATE TABLE People (
    ID int NOT NULL,
    LName varchar(255) NOT NULL,
    FName varchar(255),
    Year int,
    CONSTRAINT UC_Person UNIQUE (ID,LName)
);

SQL UNIQUE on ALTER TABLE: Example

In the example below, we produce the UNIQUE constraint after the table creation:

Example
ALTER TABLE People
ADD UNIQUE (ID);

The code example below permits naming the constraints:

Example
ALTER TABLE People
ADD CONSTRAINT UC_Person UNIQUE (ID,LName);

Note: SQL SELECT UNIQUE construct is non-standard and only supported by Oracle. For other database systems, use SQL SELECT DISTINCT.

Latest Udacity Coupon Found:

Verified STAFF PICK

75% OFF COURSES

Udacity Black Friday Offer

The best time to save on Udacity courses is now - follow this coupon to access a 75% Udacity Black Friday discount & enjoy learning at a very low cost!

Expiration date: 03/03/2021
3176 People Used
Only 97 Left
Rating
5.0