I'm designing database which some tables have modifiable PK, I want to know, is design like this good or bad? Is it make programmer hard to code?
|
feedback
|
|
Bad. If the PK is regularly changed (not as part of some reogrinanization) then it was not a natural PK or the application design is bad. | |||||||||
feedback
|
|
That sounds hard to code for. You change the primary key for a record, and you have to change all references to that primary key in all tables. Easy to mess up. Just use a sequence (or auto_increment or whatever) and make a primary key that isn't data. Or pick a primary key that's really unlikely to ever need to change. | |||||
feedback
|
|
It's kind of been said, but (my) best practice is to always name a primary key 'id' and make it a serial (autoincrement integer) (identity integer in MSSQL). It's happened to my on many occasions that I had to change the PK when it was some kind of natural key like someone's name. | |||
feedback
|
ON UPDATE CASCADE, you relatively safe (although updating such a name might trigger a lot of FK updates). – pascal Jul 28 '10 at 8:51