Contents
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.
Pros Main Features
- 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
- Free certificates of completion
- Focused on data science skills
- Flexible learning timetable
Pros Main Features
- Simplistic design (no unnecessary information)
- High-quality courses (even the free ones)
- Variety of features
- Nanodegree programs
- Suitable for enterprises
- Paid Certificates of completion
Pros Main Features
- A wide range of learning programs
- University-level courses
- Easy to navigate
- Verified certificates
- Free learning track available
- University-level courses
- Suitable for enterprises
- Verified 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.