我想删除一个名为 id
的列这是一个自动递增的 PK。
SQL:
alter table "CO88GT"."XGLCTL" drop column id cascade;
我得到:
Error: [SQL0952] Processing of the SQL statement ended. Reason code 10.
SQLState: 57014
ErrorCode: -952
我可能是错的,但我认为这与防止表丢失数据有关。为了解决这个问题,我需要创建一个没有列的新表,并将旧表中的数据复制到新表中,然后用新表替换旧表。
最佳答案
信息
由于可能丢失数据,AS400 向您发出警告(查询消息),要求您取消或忽略请求的操作。因此,由于这是一个交互式请求,因此在 JDBC/ODBC 上您不能键入“I”来忽略,并且 AS 会向您抛出一个 ErrorCode: -952 with SQLState: 57014 和 Reason code 10。
在 SQL0952 的文档中说:
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.
如果您使用的是 JDBC 并且 SQL 错误不言自明,您可以使用参数“”建立 JDBC 连接。错误=完整 ',这将提供有关错误的更多信息。其他连接参数见 this .
示例连接字符串:
jdbc:as400://serverName;libraries=*libl;naming=system;errors=full;
通过该连接,产生的错误将是这样的:
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
解决方案
所以最后,如果你不能使用 STRSQL,另一种解决方案是使用 iSeries Navigator,确切地说是它的“运行 SQL 脚本”(它通常在这里 -->“%Program Files%\IBM\Client Access\Shared\cwbundbs.exe ”)。
但首先你必须添加一个系统回复参数( 每台机器只有一次 )
ADDRPYLE SEQNBR(1500) MSGID(CPA32B2) RPY('I')
这是在“绿屏”中完成的。这会在 CPA32B2 查询消息上设置默认答案 ('I')。 CPA32B2 是一个内部消息 ID,它与删除列操作相关联。
(它实际上不必在“绿屏”中完成,像 CHGJOB 命令一样使用它。示例:
cl: ADDRPYLE SEQNBR(1500) MSGID(CPA32B2) RPY('I');
)
现在您可以开始“运行 SQL 脚本”,要运行的第一个命令是:
cl: CHGJOB INQMSGRPY(*SYSRPYL);
这会更改当前作业参数 INQMSGRPY , 到 *SYSRPYL。 *SYSRPYL 导致在应显示查询消息时查看是否存在系统回复参数。
现在您可以运行删除列的更改。
不幸的是,我不知道如何删除列,只是使用 JDBC。如果有人知道请告诉我。
引用:
关于DB2 400 删除列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4504548/