79673149

Date: 2025-06-20 09:36:38
Score: 1.5
Natty:
Report link

Just be careful about the answer provided by @sarin.

If you have any tables that reference that primary key as a foreign key, you will loose those links and perhaps even those records if you have cascade on delete rules.

What you should do rather is re-think your table design. If there is a need to change a field that is designated as the primary key, then perhaps that field is not a good candidate for a primary key.

So as a step by step, for your situation (I realize this is 10 years later), but this is what you should do for others that might have this issue.
1. Change the primary key to be your auto-increment field (or add it if it doesn't exist) (eventid as per above)
2. Create a UNIQUE index on the field that was the primary key (jobid as per above)

Your foreign keys should still be in tact. If the above fails (depends on your database), you may need to first remove all the foreign keys and recreate them afterwards. Be sure to keep the rules in tact (on delete, on update).

If you have an active database, this will all need to be done as a transaction.

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • User mentioned (1): @sarin
  • Low reputation (1):
Posted by: Glen Boonzaier