UNIQUE

SQL UNIQUE Keyword

The UNIQUE constraint ensures that all values in a column (or a combination of columns) are unique. This helps maintain data integrity by preventing duplicate values in specified columns.

Tutorials dojo strip

SQL UNIQUE Constraint on CREATE TABLE Syntax

SQL

SQL UNIQUE Constraint on CREATE TABLE Example

This query creates a Rooms table with a room_id column that must contain unique values.

SQL

SQL UNIQUE Constraint on Multiple Columns Syntax

SQL

SQL UNIQUE Constraint on Multiple Columns Example

This query creates a LabBookings table where the combination of lab_id and booking_date must be unique.

SQL

SQL UNIQUE Constraint on ALTER TABLE Syntax

SQL

SQL UNIQUE Constraint on ALTER TABLE Example

SQL

Note: This example does not work in the TechKubo playground. In SQLite, UNIQUE constraints must be defined during CREATE TABLE, not added later with ALTER TABLE.

SQL UNIQUE Constraint on ALTER TABLE with Constraint Name Syntax

SQL

SQL UNIQUE Constraint on ALTER TABLE with Constraint Name Example

SQL

Note: This example does not work in TechKubo playground. SQLite allows UNIQUE to be added only at table creation, not via ALTER TABLE.

SQL DROP UNIQUE Constraint Syntax

SQL

SQL DROP UNIQUE Constraint Example (MySQL)

SQL

Note: This example does not work in TechKubo playground. SQLite does not support dropping a named UNIQUE constraint directly. You would need to recreate the table without the UNIQUE constraint.

SQL UNIQUE Labs

Tutorials dojo strip