Re: Restructuring a table

From: Sampsa Sohlman (sampsa_sohlman_at_hotmail.com)
Date: 12/19/03


Date: Sat, 20 Dec 2003 00:53:56 +0200

Ike wrote:
> Suppose I have a table, and it is populated with many rows already. However,
> I realise I structured something wrong in my table. I dont want to have to
> go back and repopulate the entire table.
>
> For example, suppose I have a field:
>
> "inoutstatus INTEGER(3),"
>
> Which I now realize should be :
>
> "inoutstatus CHAR(1),"
>
> Is there a way I can change the entire table without losing the other
> records in each row? I can go back in and repopulate the inoutstatus fields,
> but I really would like to know if there is merely some type of SQL command
> I can issue to restructure the table this way.

I don't know which is your database platform, but I would quess that it
would go someting like this.

SELECT CAST( inoutstatus AS INT ), here_other_columns INTO new_table
FROM old_table

Instead of CAST you might have you some other function which is specific
to your database like CONVERT

- Sampsa

-- 
     -------------------------------------------
    // Sampsa Sohlman                        //
   //  My email can be found on my homepage //
  //   http://sampsa.sohlman.com           //
-------------------------------------------