mysql unique key code example

Example 1: how to add unique constraint in mysql table

ALTER TABLE mytbl ADD UNIQUE (columnName);

Example 2: how to remove unique key in mysql

ALTER TABLE mytable DROP INDEX key_Name;

Example 3: mysql alter table set column unique

ALTER TABLE contacts
ADD CONSTRAINT contacts_unique UNIQUE (reference_number);

Example 4: set column as unique in sql server

ALTER TABLE Persons
ADD UNIQUE (ID);

Example 5: sql unique

This constraint ensures all values in a column are unique.
Example 1 (MySQL): Adds a unique constraint to the id column when
creating a new users table.
CREATE TABLE users (
id int NOT NULL,
name varchar(255) NOT NULL,
UNIQUE (id)
);
Example 2 (MySQL): Alters an existing column to add a UNIQUE
constraint.
ALTER TABLE users
ADD UNIQUE (id);

Tags:

Sql Example