MySQL: Create a Unique Composite Key

June 3, 2009

I have a lookup table where I am using a composite key which must be unique. I was not sure if MySQL was able to do this or not, but I very quickly found out. It is quite a simple operation actually. I already had a table in existence so I simply altered it.

ALTER TABLE `TableName` ADD UNIQUE KEY (KeyOne, KeyTwo, ...);

There ya go. Use it, have fun with it. Share it. Try not to eat it. Your boss will not appreciate having to purchase a new monitor.