sql

Add Unique Constraints on Column in MySQL

-- WHILE CREATING TABLE ON SINGLE COLUMN
CREATE TABLE table_name(
    column_name_1  data_type UNIQUE
);

-- OR YOU CAN ADD LIKE BELOW
CREATE TABLE table_name(
   column_name_1 data_type,
   UNIQUE(column_name_1)
);

-- ADD BY COMBINING MORE THAN ONE COLUMN WHILE CREATING TABLE
CREATE TABLE table_1(
   column_name_1 data_type,
   column_name_2 data type,
   UNIQUE(column_name_1,column_name_2)
);
Was this helpful?