Categories
Database MySQL

Adding a UNIQUE constraint to a database column

Sometimes we may need to make a column unique in a database table.  For instance we can't have two employees with the same employees with the same employee number or pension plan id.

To prevent this, run a query like the following to place a constraint on the attribute or attributes;

ALTER TABLE Employee ADD UNIQUE (EmpID, PensionID)

There are many other uses of the ALTER command that will help us modify our existing tables.  See this article for more useful applications of the ALTER command.

Leave a Reply