Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove Column from Table

Status
Not open for further replies.

rhnewfie

Programmer
Jun 14, 2001
267
CA
Can someone tell me how to remove a column from a table using SQL?

Thanks
RHNewfie There are 3 Types of People in the World
Those Born to Think Logically
Those that can Learn to Think Logically
Those that Shouldn't Try
 
I don't believe there is a way to just drop a column from a table. Probably due to the possible effect on Primary and Foreign Keys (Referential Integrity as a whole.)

You'll need to do this:

Create table NewTable(
ID integer,
Data1 Char(9),
Data2 Char(16),
Amount Decimal (13,2) )

;
Then DO

Insert into NewTable
Select ID, Data1, Data2, Amount
From OldTable

;
Where you don't copy the unwanted column over to NewTable
Then Do

Drop OldTable;
 
PruSQLer

You are correct, I ended up copying the data, dropping the table, recreating the table and then repopulating it with the data I wanted to have left behind and reestablicshing foreign keys. Seems like a hokey way to have to do it but it works.

Thanks
RHNewfie There are 3 Types of People in the World
Those Born to Think Logically
Those that can Learn to Think Logically
Those that Shouldn't Try
 
While moving your records, I don't suggest using SQL statements,instead use the "export" function in control center then try using the "load".It is more reliable and very much faster. Salih Sipahi
Software Engineer.
City of Istanbul Turkey
openyourmind77@yahoo.com
 
Hattusas

Excuse my ignorance but is that something that I could do from a vb front end?

RHNewfie There are 3 Types of People in the World
Those Born to Think Logically
Those that can Learn to Think Logically
Those that Shouldn't Try
 
You have DB2 in your system correct?What versioon of DB2 do you have? Salih Sipahi
Software Engineer.
City of Istanbul Turkey
openyourmind77@yahoo.com
 
I have DB2 version 7 that I am using for my backend with a VB front end.

RHNewfie There are 3 Types of People in the World
Those Born to Think Logically
Those that can Learn to Think Logically
Those that Shouldn't Try
 
Do you need to reconstruct your table from your clients???
I don't think it is secure.You should never grant your users to drop your database tables.These transactions should be performed in local or remote DB2 systems.
Export and import commands are in the control center part of your DB2 software.
Open your control center,then yoru database and open your tables.Select your table click right mouse and select export.Fill the required fields then in your target table you can both perform the import or load functions.
You can find documnets in information center of DB2 software Salih Sipahi
Software Engineer.
City of Istanbul Turkey
openyourmind77@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top