![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have a record in my database. The index key is Patient_ID I want to modify the record because the patients name has changed or their ID has changed. The simple way to do this would be to delete the record and add a new one. |
|
But what happens in the case of a relational database were deleting the record would delete relations in other tables? |
|
What SQL statement would do this properly? UPDATE table-1 SET set-list [WHERE predicate] |
#3
| |||
| |||
|
|
I have a record in my database. The index key is Patient_ID I want to modify the record because the patients name has changed or their ID has changed. The simple way to do this would be to delete the record and add a new one. |
|
But what happens in the case of a relational database were deleting the record would delete relations in other tables? |
#4
| |||
| |||
|
|
But what happens in the case of a relational database were deleting the record would delete relations in other tables? |
#5
| |||
| |||
|
|
Now, I'm just wondering: how can a patient's ID get changed? Wasn't the person the one he claimed to be, or has he undergone a severe Identity Transplantation? |
|
-- Erick |
#6
| |||
| |||
|
|
SpreadTooThin: I have a record in my database. The index key is Patient_ID I want to modify the record because the patients name has changed or their ID has changed. The simple way to do this would be to delete the record and add a new one. That would be the 'same' as kkilling the person, and giving birth to a new one, who you are going to dress up like the old one. If names and IDs can change, they should be normal attributes of the Patient entity. Patient should then be identified by something else. Perhaps just an autoincrement value. So, perhaps you could first convert the table, so the ID field gets copied into a new field 'notReallyAnID". Then change that field and treat it as the display-value for ID. But what happens in the case of a relational database were deleting the record would delete relations in other tables? You'd be in trouble, unless you can restore the relationships after deleting and inserting (which is what you don't want to do). Now, I'm just wondering: how can a patient's ID get changed? Wasn't the person the one he claimed to be, or has he undergone a severe Identity Transplantation? |
| |
#7
| |||||
| |||||
|
|
I have a record in my database. The index key is Patient_ID I want to modify the record because the patients name has changed or their ID has changed. The simple way to do this would be to delete the record and add a new one. That would be the 'same' as kkilling the person, and giving birth to a new one, who you are going to dress up like the old one. If names and IDs can change, they should be normal attributes of the Patient entity. Patient should then be identified by something else. Perhaps just an autoincrement value. So, perhaps you could first convert the table, so the ID field gets copied into a new field 'notReallyAnID". Then change that field and treat it as the display-value for ID. But what happens in the case of a relational database were deleting the record would delete relations in other tables? You'd be in trouble, unless you can restore the relationships after deleting and inserting (which is what you don't want to do). Now, I'm just wondering: how can a patient's ID get changed? Wasn't the person the one he claimed to be, or has he undergone a severe Identity Transplantation? |
|
I want to modify the record because the patients name has changed or their ID has changed. Presumably here the ID and the name are different fields. |
|
Marriage, divorce, adoption, voluntary legal name change. The problem Plus, in the USA there's no law saying that twins have to have |
|
is that the OP used the patients name as the primary key for the table. |
|
The problem is that you had a poor design in the beginning. A primary key should be something that identifies a particular record FOREVER. It should not be something that can change, like a name, address, email or anything like that. The name should have been one of the field values that is in the record identified by that primary key. Usually, a simple auto-increment key is sufficient. What you have to do now is quite messy. 1 - Create a new field (primary key) in the patient table that auto-increments. 2 - Go to all tables that use the patientID as a primary key and update those tables such that it now contains the value of the new primary key you created. 3 - Go back into all your queries in your code and change the references to patientID over to the new primary key. 4 - Look in your code where you want the actual name of the patient and get that from a query based upon the new primary key. |
#8
| |||
| |||
|
|
I have a record in my database. The index key is Patient_ID I want to modify the record because the patients name has changed or their ID has changed. The simple way to do this would be to delete the record and add a new one. That would be the 'same' as kkilling the person, and giving birth to a new one, who you are going to dress up like the old one. If names and IDs can change, they should be normal attributes of the Patient entity. Patient should then be identified by something else. Perhaps just an autoincrement value. So, perhaps you could first convert the table, so the ID field gets copied into a new field 'notReallyAnID". Then change that field and treat it as the display-value for ID. But what happens in the case of a relational database were deleting the record would delete relations in other tables? You'd be in trouble, unless you can restore the relationships after deleting and inserting (which is what you don't want to do). Now, I'm just wondering: how can a patient's ID get changed? Wasn't the person the one he claimed to be, or has he undergone a severe Identity Transplantation? I don't think the ID is the name: I want to modify the record because the patients name has changed or their ID has changed. Presumably here the ID and the name are different fields. Marriage, divorce, adoption, voluntary legal name change. The problem Plus, in the USA there's no law saying that twins have to have different names. is that the OP used the patients name as the primary key for the table. No, it's quite apparent that the ID and the name are different fields. |
#9
| |||||
| |||||
|
|
Erick T. Barkhuis wrote: Now, I'm just wondering: how can a patient's ID get changed? Wasn't the person the one he claimed to be, or has he undergone a severe Identity Transplantation? Marriage, divorce, adoption, voluntary legal name change. The problem is that the OP used the patients name as the primary key for the table. |
|
The problem is that you had a poor design in the beginning. A primary key should be something that identifies a particular record FOREVER. |
|
Usually, a simple auto-increment key is sufficient. |
|
What you have to do now is quite messy. 1 - Create a new field (primary key) in the patient table that auto-increments. 2 - Go to all tables that use the patientID as a primary key and update those tables such that it now contains the value of the new primary key you created. |
|
3 - Go back into all your queries in your code and change the references to patientID over to the new primary key. 4 - Look in your code where you want the actual name of the patient and get that from a query based upon the new primary key. Have fun :-) |
#10
| |||
| |||
|
|
: Erick T. Barkhuis wrote: Now, I'm just wondering: how can a patient's ID get changed? Wasn't the person the one he claimed to be, or has he undergone a severe Identity Transplantation? Marriage, divorce, adoption, voluntary legal name change. The problem is that the OP used the patients name as the primary key for the table. Oh, I thought he used some ID number and wants to change that. Name changes happen all the time... The problem is that you had a poor design in the beginning. A primary key should be something that identifies a particular record FOREVER. Well, yes. But STT made a valid point: how would you correct a typo, then? Usually, a simple auto-increment key is sufficient. I agree. But if you have something that is a unique identifier, the temptation to use it as a key is obvious. |
|
What you have to do now is quite messy. 1 - Create a new field (primary key) in the patient table that auto-increments. 2 - Go to all tables that use the patientID as a primary key and update those tables such that it now contains the value of the new primary key you created. Hmm....as I posted before, I wouldn't do that. Too much hassle and risk. Instead, I would keep the old PKs and add the IDfield as an attribute. 3 - Go back into all your queries in your code and change the references to patientID over to the new primary key. 4 - Look in your code where you want the actual name of the patient and get that from a query based upon the new primary key. Have fun :-) Yeah, right. |
![]() |
| Thread Tools | |
| Display Modes | |
| |