Answer: The UNIQUE Constraint
Find a detailed explanation of how to use the UNIQUE constraint on columns of an existing table.
Solution
The solution is given below:
Press + to interact
MySQL
/* Applying UNIQUE contraint on EmpName */ALTER TABLE Employees ADD UNIQUE (EmpName);/* Inserting a new record in the table */INSERT INTO Employees VALUES (5, 'Susan Lee', 5000);/* Retrieve the records in the table */SELECT * FROM Employees;
Explanation
The explanation of the solution code is given below:
Line 2: The
ALTER TABLEquery modifies a table.ADDis used to add a constraint.UNIQUEtakes in a column name as a parameter and applies a unique constraint on that column.Line 5: The
INSERT INTOstatement is followed by the table name,Employees, which will be modified. TheVALUESclause specifies the values.Line ...
Ask