views:

93

answers:

2

I have a database by name database1 and it contain a table by name of employee In employee table have many fields like employee, name, salary etc etc.

by mistake i am change salary value 0 for all employee.

I am restore database from backup by name database2

Now i need assistance to update my current database which is database1

I want to put the value of Salary column in table employee from database2 to my current database which is database1 in same employee table salary column.

common in both employee table, it contain employee column which is common.

sql 2005 server using

need urgent help

A: 

You are going to need to do a cross database query, below is an example.

Assumptions

  1. This is being ran on Database1 with an account that has access to Database2
  2. The table on Database2 in in the dbo schema
  3. You have FULL backups of EVERYTHING
  4. The EmployeeId field is the primary key on the table

Query THis query works on MS SQL Server and has been tested, but BE SURE TO HAVE BACKUPS just in case!!

UPDATE Employee 
SET Salary = b.Salary
FROM Employee A
    INNER JOIN database2.dbo.Employee B
     ON (A.EmployeeId = B.EmployeeId)
Mitchel Sellers
Msg 4104, Level 16, State 1, Line 1The multi-part identifier "A.salary" could not be bound.
updated the posting
Mitchel Sellers
+2  A: 
UPDATE database1.employees
SET salary = e2.salary
FROM database1.employees AS e1
INNER JOIN database2.employees AS e2
    ON e2.employeecode = e1.employeecode
Cade Roux
Msg 208, Level 16, State 1, Line 1Invalid object name 'database1.employees'.
try adding dbo. in the table names so that it is databasename.dbo.tablename (eg. database1.dbo.employees)of course that assume dbo owns your tables...
mundeep