I have a table: event_list with two columns: name as var(80) and default as ENUM(‘y’,’n’).
The idea is that there can only be one event set as default at a time. So if there are 100 events in the table 99 of them must have a default value of ‘n’ and one must have a default value of ‘y’.
When a customer is adding a new event to the system there is a option “Make This Event Default”. What I want to do is insert the event into the table. If the default column for that insert is added as ‘y’ I need a easy way of changing all the rest of the default rows to ‘n’.
Is there a way for mySQL to handle this or will I have to manually change all the other data fields to ‘n’ if the user makes a new default?
I would suggest altering your current table to include an ID (unique, autoincrement) field, and removing the enum field, and then adding a new table that stores the ID of default event. Then you only need to edit one line.