Is it possible to have an unique index on multiple columns, of which a column with type
enum is part of?
Let's say I have 3 columns, which are an unique index, combined:
date is just a date,
companyId is an integer, but
type is an enum, which could be
month. Reason to have this, is because the table contains imported statistics. A company has only one row per date, per type. The index is to prevent data will be imported twice, accidentally.
I tried the following which did not work:
ALTER TABLE `stats` ADD UNIQUE INDEX `unique_index` (`companyId`, `date`, `type`);
The error I received was:
MySQL said: Duplicate entry '288837-2017-05-15-' for key 'unique_index'
As you can see the key doesn't contain the type, only the