Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DB2 400 drop column

I want to drop a column called id which is an auto incrementing PK.

The SQL:

alter table "CO88GT"."XGLCTL" drop column id cascade;

And I get:

Error: [SQL0952] Processing of the SQL statement ended.  Reason code 10.

SQLState:  57014

ErrorCode: -952

I could be wrong but I think it has something to do with preventing the table from losing data. To get around this issue I need to create a new table without the column and copy the data from the old table into the new table and then replace the old table with the new table.

like image 983
Quaternion Avatar asked Dec 21 '10 22:12

Quaternion


People also ask

How do I drop a column in DB2?

You can delete a column using the DROP COLUMN clause of the ALTER TABLE statement. Dropping a column deletes that column from the table definition. If CASCADE is specified, any views, indexes, and constraints dependent on that column will also be dropped.

How do you drop a table in DB2?

To drop a table, use a DROP TABLE statement. To drop all the tables in a table hierarchy, use a DROP TABLE HIERARCHY statement. The DROP TABLE HIERARCHY statement must name the root table of the hierarchy to be dropped.

How do I add multiple columns in DB2?

In this syntax: First, specify the name of the table to which you want to add the new column in the ALTER TABLE clause. Second, specify the new column including name, data type, and column constraint in the ADD COLUMN clause.

How do I change the column length in DB2?

In DB2 9.7 for Linux/UNIX/Windows, you can use the ALTER TABLE statement to reduce the length of a column, assuming that no values in the column exceed the new column size: ALTER TABLE temp ALTER COLUMN col1 SET DATA TYPE VARCHAR(60); If any values in the column exceed the desired size you must handle that first.

How do I drop a column in a DB2 table?

Summary: in this tutorial, you’ll learn how to drop one or more columns in a table by using the Db2 ALTER TABLE DROP COLUMN statement. Sometimes, you may want to delete one or more unused columns from a table. To do this, you use the ALTER TABLE DROP COLUMN statement as follows:

How to change the default value of a column in DB2?

First, specify the name of the table which you want to perform the change in the ALTER TABLE clause. Second, specify the name of the column that you want to modify. Third, add a clause as a modification type. Db2 allows you to change the data type of a column, adjust the column length, and change the default value to a new one.

How do I drop a column from a table in razorsql?

The RazorSQL alter table tool includes a Drop Column option for dropping a column from a DB2 database table. The drop column function allows the user to select a column to drop from the table. The tool then generates the appropriate alter table drop column SQL command for dropping the column from the table.

How do I delete or drop a column in a table?

To delete or drop a column, issue the ALTER TABLE statement with the DROP COLUMN clause.


1 Answers

Info

AS400 is giving you a warning (inquiry message) because of possible data loss, asking you to Cancel or Ignore the requested operation. So, beacuse of this being a interactive request, over JDBC/ODBC you cannot type 'I' to ignore, and AS throws you an ErrorCode: -952 with SQLState: 57014 and Reason code 10.

In the documentation of SQL0952 says:

Message Text:   Processing of the SQL statement ended. Reason code &1.
Cause Text:     The SQL operation was ended before normal completion. The reason code is &1. Reason codes and their meanings are:

* 1 - An SQLCancel API request has been processed, for example from ODBC.
* 2 - SQL processing was ended by sending an exception.
* 3 - Abnormal termination.
* 4 - Activation group termination.
* 5 - Reclaim activation group or reclaim resources.
* 6 - Process termination.
* 7 - An EXIT function was called.
* 8 - Unhandled exception.
* 9 - A Long Jump was processed.
* 10 - A cancel reply to an inquiry message was received.
* 11 - Open Database File Exit Program (QIBM_QDB_OPEN).
* 0 - Unknown cause.

If you are using JDBC and the SQL error isn't self-explanatory, you can make a JDBC connection with parameter 'errors=full', which will give much more info on the error. For other connection parameters see this.

example connection string:

jdbc:as400://serverName;libraries=*libl;naming=system;errors=full;

With that connection the resulting error would be like this:

Error: [SQL0952] Processing of the SQL statement ended.  Reason code 10.
Cause . . . . . :   The SQL operation was ended before normal completion.
The reason code is 10.
Reason codes and their meanings are:
1 -- An SQLCancel API request has been processed, for example from ODBC.
2 -- SQL processing was ended by sending an exception.
3 -- Abnormal termination.
4 -- Activation group termination.
5 -- Reclaim activation group or reclaim resources.
6 -- Process termination.
7 -- An EXIT function was called.
8 -- Unhandled exception.
9 -- A Long Jump was processed.
10 -- A cancel reply to an inquiry message was received.
11 -- Open Database File Exit Program (QIBM_QDB_OPEN).
0 -- Unknown cause.
Recovery  . . . :   If the reason code is 1, a client request was made to cancel SQL processing.  For all other reason codes, see previous messages to determine why SQL processing was ended.

SQLState:  57014
ErrorCode: -952

The solution

So finally, if you cannot use STRSQL, another solution is to use iSeries Navigator, to be exact its "Run SQL scripts" (it is usually here --> "%Program Files%\IBM\Client Access\Shared\cwbundbs.exe").

But first of all you have to add a system reply parameter (only once per machine)

ADDRPYLE SEQNBR(1500) MSGID(CPA32B2) RPY('I')

This is done in "green screen". This sets a deafult answer ('I') on CPA32B2 inquiry message. The CPA32B2 is an internal massage id, which is tied to an drop column operation.

(It actually doesn't have to be done in "green screen", use it like CHGJOB command. Example :

cl: ADDRPYLE SEQNBR(1500) MSGID(CPA32B2) RPY('I');

)

Now you can start "Run SQL scripts", the first command to run is:

cl: CHGJOB INQMSGRPY(*SYSRPYL);

this changes the current job parameter INQMSGRPY, to *SYSRPYL. *SYSRPYL causes to look if exists a system reply parameter when an inquiry message should be displayed.

Now you can run your alter which drops the column.


Unfortunately, I don't know how to drop a column, just using JDBC. If someone knows please let me know.

References:

  • Understanding What Controls the Automatic Reply Function
  • Replying to Run-Time Inquiry Messages
  • Error in dropping column (forum post)
  • How can I avoid SQL0952 on ALTER TABLE?
like image 193
3 revs Avatar answered Sep 22 '22 05:09

3 revs