🚨 Get Your Free NFT Certificate Mint by Completing the Web3 Exam! START NOW

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.
DataCamp
Pros
  • Easy to use with a learn-by-doing approach
  • Offers quality content
  • Gamified in-browser coding experience
  • The price matches the quality
  • Suitable for learners ranging from beginner to advanced
Main Features
  • Free certificates of completion
  • Focused on data science skills
  • Flexible learning timetable
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
Udemy
Pros
  • Easy to navigate
  • No technical issues
  • Seems to care about its users
Main Features
  • Huge variety of courses
  • 30-day refund policy
  • Free certificates of completion

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.