tags:

views:

45

answers:

2

I make a mistake and I have done a wrong update on my main database (hospital) (blood types have been unknown for most of patients in tblPatientFile table) but I have a daily backup database (hospitalRapor) and data are true for patients before today( and it is about 400000 records)

can I copy my old data from like this [hospital].[dbo].[tblPatientFile].[bloodTypeField] = [hospitalRapor].[dbo].[tblPatientFile].[bloodTypeField] where [hospital].[dbo].[tblPatientFile].[patientId] = [hospitalRapor].[dbo].[tblPatientFile].[patientId]

I am on trouble guys, I have to fix this situation in this day. thanks for helps

A: 

I take it you have a restore of the database on the same server, in which case assuming all the previous data was correct you could, although you would overwrite any updates to the blood type that have been made since your error.

I would suggest you also backup your 'incorrect' database before you go any further, so that an additional mistakes can be rectified - undone easily so you can at least return to the initial 'error' state instead of compounding problems.

Andrew
yes I take list of blood types from backup database, and saved it to an excell file
Rapunzo
+1  A: 

You didn't say a database server, so I can't be sure this will work, but I believe the syntax on MSSQL would be:

UPDATE livefile
SET livefile.bloodtypefield=oldfile.bloodtypefieild
FROM [hospital].[dbo].[tblPatientFile] livefile
INNER JOIN [hospitalRapor].[dbo].[tblPatientFile] oldfile on livefile.patientid=oldfile.patientid

I highly recommend running on a test database first to make sure it has the results you want. You will of course need a user who has access to both databases and depending on whether you have triggers etc defined that may take a long time to run on 400k rows.

Tim Schneider