![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, we have a Fk pointing to a parent table/column - and now sadly enough that primary key value will change. What would be a smart way to implement this change to these child tables ? Disabling FK's and a lot of update clauses or .... ?? BR, timo |
#3
| |||
| |||
|
|
Op 26-2-2010 9:36, eh schreef: Hi, we have a Fk pointing to a parent table/column - and now sadly enough that primary key value will change. What would be a smart way to implement this change to these child tables ? Disabling FK's and a lot of update clauses or .... ?? BR, timo If it changes, it's not a primary key... Anyway, if there are no other unique keys on the master table, do not change the key, but copy the record with a new pk, restore child connections by updating the foreign keys and delete or archive the original master record. Note that while performing these actions, queries may give wrong results (sum, count, etc). Shakespeare |
#4
| |||
| |||
|
|
On Feb 26, 4:56 am, Shakespeare<what... (AT) xs4all (DOT) nl> wrote: Op 26-2-2010 9:36, eh schreef: Hi, we have a Fk pointing to a parent table/column - and now sadly enough that primary key value will change. What would be a smart way to implement this change to these child tables ? Disabling FK's and a lot of update clauses or .... ?? BR, timo If it changes, it's not a primary key... Anyway, if there are no other unique keys on the master table, do not change the key, but copy the record with a new pk, restore child connections by updating the foreign keys and delete or archive the original master record. Note that while performing these actions, queries may give wrong results (sum, count, etc). Shakespeare Shakespeare has given the correct sequence for the process where it is necessary to update a PK to a new value. I will agree that as a general rule a PK should not change; however, in the real world it is sometimes necessary to change a PK which is why the ANSI standard requires that PK in fact be updatable. Mergers and acquisition activity often leads to the need to re-key information where the two merged parties had overlap in vendors or customers. But if you find it necessary to update a PK value which in turn requires updating related data on a regular basis then you do need to re-examine the choice of PK. HTH -- Mark D Powell -- |
#5
| |||
| |||
|
|
On Feb 26, 4:56*am, Shakespeare <what... (AT) xs4all (DOT) nl> wrote: Op 26-2-2010 9:36, eh schreef: Hi, we have a Fk pointing to a parent table/column - and now sadly enough that primary key value will change. What would be a smart way to implement this change to these child tables ? Disabling FK's and a lot of update clauses or .... ?? BR, timo If it changes, it's not a primary key... Anyway, if there are no other unique keys on the master table, do not change the key, but copy the record with a new pk, restore child connections by updating the foreign keys and delete or archive the original master record. Note that while performing these actions, queries may give wrong results (sum, count, etc). Shakespeare Shakespeare has given the correct sequence for the process where it is necessary to update a PK to a new value. *I will agree that as a general rule a PK should not change; however, in the real world it is sometimes necessary to change a PK which is why the ANSI standard requires that PK in fact be updatable. *Mergers and acquisition activity often leads to the need to re-key information where the two merged parties had overlap in vendors or customers. But if you find it necessary to update a PK value which in turn requires updating related data on a regular basis then you do need to re-examine the choice of PK. HTH -- Mark D Powell -- |
#6
| |||
| |||
|
|
Hi, we have a Fk pointing to a parent table/column - and now sadly enough that primary key value will change. What would be a smart way to implement this change to these child tables ? Disabling FK's and a lot of update clauses or .... ?? |
#7
| |||
| |||
|
|
Hi, we have a Fk pointing to a parent table/column - and now sadly enough that primary key value will change. What would be a smart way to implement this change to these child tables ? Disabling FK's and a lot of update clauses or .... ?? BR, timo |
#8
| |||
| |||
|
|
Problem with classic relational theory, it lacks time dynamism, it's not always just another attribute as you discover unelocuted requirements. |
#9
| |||
| |||
|
|
Hi, we have a Fk pointing to a parent table/column - and now sadly enough that primary key value will change. What would be a smart way to implement this change to these child tables ? Disabling FK's and a lot of update clauses or .... ?? |
#10
| |||
| |||
|
|
"joel garry" <joel-ga... (AT) home (DOT) com> wrote in message news:9fa0cb07-904e-421f-b265-d0e5ff234981 (AT) g28g2000prb (DOT) googlegroups.com... * * * * * * * * * * * * * * * * * ** * * * * * * * * * Problem with classic *relational theory, it lacks time dynamism, it's not always just *another attribute as you discover unelocuted requirements. Not a problem - Chris Date cracked that a few years ago with a Hugh Darwen and another persons whose name I forget. *Resulted in 6th Normal form, which collapsed to 5th Normal form in the absence of time- dependency and time-dependent operators. |
|
I think someone from Oracle had a presentation about their work in the same area a couple of years ago. It allows "convenient" (though not necessary efficient) handling of queries like: What would the data have looked like if I had queried it on 10th Feb allowing for the fact that there was an error on 9th Feb that wasn't corrected until 11th Feb - and I want to see the correct item, not the error. |
![]() |
| Thread Tools | |
| Display Modes | |
| |