Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
ntn104
Posting Yak Master
175 Posts |
Posted - 2009-07-07 : 09:04:09
|
| Hello,How do I merge one account to another account. Please see below for data:Account 1:ID=1234Account 2: ID=5678I want to merge account 1 into account 2 and delete account 1. I wonder if I can do like this. Thanks,update t2 setid=1234from table as t2whereid =5678and delete id=1234 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2009-07-07 : 09:07:44
|
| Depends what constraints you have on the table and whether you have any foreign keys. If you have reference data in other tables, you will need to look into getting that sorted first. Once you have done this, you can quite easily just delete this record if you already have all of the rest of the information on your current 1234 account. |
 |
|
|
ntn104
Posting Yak Master
175 Posts |
Posted - 2009-07-07 : 09:12:22
|
quote: Originally posted by RickD Depends what constraints you have on the table and whether you have any foreign keys. If you have reference data in other tables, you will need to look into getting that sorted first. Once you have done this, you can quite easily just delete this record if you already have all of the rest of the information on your current 1234 account.
But there some reference data under account id=1234 that need to be merge to account id=5678. If I delete 1234, then some information like case_id under 1234 will be delete and can not merge with id=5678. |
 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2009-07-07 : 09:46:00
|
| So you'll have to update the reference data first, as I said. Once this is done, you can then delete the other record. I am guessing that accountid is your primary key, so having duplicates is not good practice and if you have set it to be a primary key, you will have a constraint violation.Update the record you want to keep with the information from the other record first and then delete the other one.Check any other tables for reference data before you delete the record. |
 |
|
|
ntn104
Posting Yak Master
175 Posts |
Posted - 2009-07-07 : 09:51:59
|
quote: Originally posted by RickD So you'll have to update the reference data first, as I said. Once this is done, you can then delete the other record. I am guessing that accountid is your primary key, so having duplicates is not good practice and if you have set it to be a primary key, you will have a constraint violation.Update the record you want to keep with the information from the other record first and then delete the other one.Check any other tables for reference data before you delete the record.
Thank you! I guess I have to update reference data first as you said. |
 |
|
|
|
|
|
|
|