MySQL Multiple Unique Index

I recently had a project with an old table that didn’t have any unique keys but REALLY needed some. The table in question had columns with huge values. For instance the FirstName column had a VARCHAR(255) and same with last name and THE SAME WITH DOB!!!!! OK, well whatever, lets just add a unique key to those 3 columns to ensure we do not get a duplicate person.

That didn’t work. The unique indexes on a MySQL table can only account for so many characters. Even just the FirstName column was too long to set as a unique index by itself. So I had to find a work around and, thankfully, there is a really easy, really awesome, way to do this. You can just choose your columns AND the amount of characters in each of those columns to check.

Here is that query.