Adding a Unique Key with ALTER TABLE
Using the ALTER TABLE statement, you can add a UNIQUE constraint to an existing table.
ALTER TABLE products
ADD CONSTRAINT unique_product_code UNIQUE (product_code);
After adding a Unique constraint with ALTER TABLE table structure will be.
Explanation: This ALTER TABLE statement adds a new UNIQUE constraint named unique_product_code to the product_code column within the products table. This constraint ensures that each product code remains unique, preventing duplicates from being inserted.
MySQL UNIQUE Constraint
MySQL UNIQUE constraint ensures that the values in a column or group of columns remain unique, preventing duplicate entries in a column and maintaining the integrity of the table.