Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / December 2003

Tip: Looking for answers? Try searching our database.

Restructuring a table

Thread view: 
Ike - 19 Dec 2003 18:42 GMT
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.

Thanks, Ike
Sampsa Sohlman - 19 Dec 2003 22:53 GMT
> 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
[quoted text clipped - 12 lines]
> 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

Signature

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

Silvio Bierman - 20 Dec 2003 00:23 GMT
> 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
[quoted text clipped - 14 lines]
>
> Thanks, Ike

Look into ALTER TABLE statements. Beware of conversion issues when changing
the type of a column.

Silvio Bierman
brougham5@yahoo.com - 20 Dec 2003 00:40 GMT
>"inoutstatus INTEGER(3),"
>
>Which I now realize should be :
>
>"inoutstatus CHAR(1),"

Look for the commands drop and alter.  Drop the column, and then alter the
table to add a new column.  You may need to do that in two stages...add a
column that accepts nulls, add your values, and then alter it again not to
accept null values if that's what you want the end result to be.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.