Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When would you ever need to change a primary key's value?

I've been reading up on foreign keys and such for postgres and I noticed that it allows a cascading update for foreign keys.

Well, my question is, when would you need to update the primary key of a row?

Apparently this guy needs to http://www.oreillynet.com/onlamp/blog/2004/10/hey_sql_fans_check_out_foreign.html but I'm not quite understanding how it could ever be useful.

Edit: I see for natural primary keys, how this could be used. But what about technical primary keys? Ones that have no meaning and are almost always auto generated on insert?

like image 932
Earlz Avatar asked Dec 11 '25 07:12

Earlz


1 Answers

Well... we have a lot of primary keys that are defined as a human readable code. Terrible idea, but not much choice in the matter.

It is very very handy to be able to fix that PK, and all dependent records, when someone realizes it is misspelled, or the meaning has changed.

like image 140
Andrew Avatar answered Dec 12 '25 19:12

Andrew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!