Search code snippets, questions, articles...

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)
);
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool
Was this helpful?
0 Comments