List:General Discussion« Previous MessageNext Message »
From:SGreen Date:October 21 2005 12:54am
Subject:Re: Dropped a field, need fix emergency
View as plain text  
Scott Haneda <lists@stripped> wrote on 10/20/2005 08:11:27 PM:

> I dropped a field in a table, I have a backup, so is what I have done is
> imported the backup of the table to a new table, so I have table 
"sessions"
> which has a empty field for "session_key"
> 
> I now have sessions_backup which has all the data, there is a pk called 
id
> 
> I need to run a sql update that will pull the session_key from the 
backup
> table, and update the sesssions table with it, based in the field id=id.
> 
> Can someone help me, I am pretty sure I know what to do, but don't want 
to
> risk messing it up.
> 
> thanks
> -- 
> -------------------------------------------------------------
> Scott Haneda                                Tel: 415.898.2602
> <http://www.newgeo.com>                     Novato, CA U.S.A.
> 
> 

Assuming that your MySQL version supports multiple table updates:

UPDATE sessions s 
INNER JOIN sessionbackup sb 
        ON sb.id = s.id
SET s.session_key = sb.session_key;

even if this screws up (which it really shouldn't), you can re-blank your 
session_key and try again with:

UPDATE session
SET session_key = NULL;

Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine

Thread
Dropped a field, need fix emergencyScott Haneda21 Oct
  • Re: Dropped a field, need fix emergencySGreen21 Oct