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 |
pineappleflower
Starting Member
6 Posts |
Posted - 2008-12-15 : 23:08:03
|
One of my table in my current database data is wrongly updated by user, I want to update it to correct value using my backup database, how can I do this?For example:TableA have field subject and ID(unique), I have installed both database in the same server, but my problem is how to write an update script to update the field from backup db to current db using ID as the key word. |
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2008-12-15 : 23:28:34
|
Something like this:update sourcedb.dbo.tablenameset sourcedb.dbo.tablename.fieldname = backupdb.dbo.tablename.fieldnamefrom sourcedb..tablenameinner join backupdb..tablenamewhere sourcedb..tablename.id = backupdb...tablename.id |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-16 : 00:02:31
|
i would prefer using aliases to prevent confusion with long namesupdate sset s.fieldname = b.fieldnamefrom sourcedb.dbo.tablename sinner join backupdb.dbo.tablename bwhere s.id = b.id |
|
|
pineappleflower
Starting Member
6 Posts |
Posted - 2008-12-16 : 00:27:49
|
When I use the query below, I hit the following error, any ideas?update sset s.subject = b.subjectfrom [990].dbo.bacodiscussions sinner join [999].dbo.bacodiscussions bwhere s.hid = b.hidError:=======Server: Msg 156, Level 15, State 1, Line 5Incorrect syntax near the keyword 'where'. |
|
|
pineappleflower
Starting Member
6 Posts |
Posted - 2008-12-16 : 00:32:22
|
I found the error, can not use WHERE clause, i use ON and it is work fine.update [990].dbo.bacodiscussionsset [990].dbo.bacodiscussions.subject = [999].dbo.bacodiscussions.subjectfrom [990].dbo.bacodiscussionsinner join [999].dbo.bacodiscussions on [990].dbo.bacodiscussions.hid = [999].dbo.bacodiscussions.hid |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2008-12-16 : 09:00:31
|
oops !! we both missed ON part. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-16 : 10:42:51
|
quote: Originally posted by sodeep oops !! we both missed ON part.
yeah.. |
|
|
pineappleflower
Starting Member
6 Posts |
Posted - 2008-12-16 : 21:21:49
|
Thanks guys |
|
|
|
|
|