SQL7008 – 为什么以及如何DB2要求用户在文件创建之前就记录日志?

huangapple go评论65阅读模式
英文:

SQL7008 - Why and how DB2 require users to journal a file even before it is created?

问题

CREATE OR REPLACE TABLE QTEMP/TESTF0( 
 ID         NUM(3) 主键,       
 STRID      CHAR(3),                  
 NUMSI      小整数,                 
 NUMI       整数,                      
 NUMBI      大整数                    
 ) RCDFMT TESTF0R;

我试图在 QTEMP 中创建一个表,但是 RUNSQLSTM 命令失败,并显示以下 ERRMSG

SQL7008  30       1  位置 1 QTEMP 中的 TESTF0 对操作无效。

我将 DDL 中的合格模式 QTEMP 去掉并重试,这次出现了一个新的错误,但是在 QGPL 中创建了一个文件对象(不确定它能否使用)。

SQL7905  20       1  位置 1  TESTF0  QGPL 中已创建但未启用日志记录。

我了解了一些关于 RUNSQLSTM 命令的微妙之处,因此我尝试将 CHGCURLIB 更改为我的测试库并重新运行命令,这次它正常工作了。

我阅读了一些关于解决 SQL7008 的帖子,它们都建议对 PF 进行日志记录。但在拥有文件对象之前是不可能的。这让我想到了,这可能是因为用户库可能会默认启用日志记录,而上述 ERRMSG 可能是由于 QGPL 在这里是一个例外,显然 QTEMP 可能永远不会启用日志记录?我很好奇。那么对于 QTEMP 表,有什么解决方法呢?

在处理这个问题时,我想到了另一个想法,这可能是一个 IBM i 支持查询/请求,但让我先听听你们的意见。鉴于 IBM 正在努力使 IBM i 现代化并更易于访问,并推动使用 DDL 而不是 DDS,为什么 RUNSQLSTM 尚未支持 *FILE 对象呢?或者是否有一个更好的系统命令,可以提示用户要将 SQL 对象创建在哪个对象库中?
英文:
CREATE OR REPLACE TABLE QTEMP/TESTF0( 
 ID         NUM(3) PRIMARY KEY,       
 STRID      CHAR(3),                  
 NUMSI      SMALLINT,                 
 NUMI       INT,                      
 NUMBI      BIGINT                    
 ) RCDFMT TESTF0R;

I'm trying to create a table in QTEMP and the RUNSQLSTM command fails with following ERRMSG

SQL7008  30       1  Position 1 TESTF0 in QTEMP not valid for operation.

I take off the qualified schema QTEMP from the DDL and retry, I get a new error this time, but with a file object in QGPL (not sure how usable it'd be).

SQL7905  20       1  Position 1 Table TESTF0 in QGPL created but was not 
                     journaled.

I know some nuances of the command RUNSQLSTM, hence I tried CHGCURLIB to my test lib and re-tried the command, and it worked fine.

I read about some posts regarding SQL7008 resolution and they all suggested to journal the PF. But that's not possible until we have the file object. That lead me to thinking, could this be possible because the user libraries may be journalled by default, and the above ERRMSGs are due to QGPL being an exception here, and apparently QTEMP may never be journalled??? I'm curious. What's the workaround then for QTEMP tables?

Another thought that came while mucking around with this issue and it could be rather an IBM i Support Query/RFE, but let me first hear you all. - Owing to the fact that IBM is trying to make IBM i modern and more accessible, and pushing the use of DDL over DDS, why is that RUNSQLSTM doesn't have a support for *FILE object yet? Or a better system command that could prompt for the object library where the user wants the SQL objects to be created?

答案1

得分: 3

SQL7008最常见的原因是表没有被记录日志,但还有其他原因,你可能遇到其中之一。SQL7008和许多消息一样,提供了有关错误的更多详细信息以及如何恢复。

你可能有10的原因代码

10 -- 向无效类型的表添加约束或触发器,或已达到触发器的最大数量,或分布式表的所有节点的发布级别不同。

你可以在QTEMP中创建表,但不能向QTEMP中的表添加约束(任何类型)或触发器,因此无法创建具有主键的表。作为解决方案,你可以在QTEMP中创建一个唯一索引,用于“约束”你的表。

有两种方法可以告诉表应该在哪个模式中使用SQL创建,在RUNSQLSTM或任何其他工具中:

  • 类似于QTEMP一样限定名称
  • 设置当前模式

但仅告诉表应该在哪里创建还不够。
在QTEMP中无法记录任何对象,这是真的,但在其他模式中,可以在使用SQL创建时自动记录表,前提是QGPL未填写的条件:

  • 库中存在一个名为QSQJRN的日志,CREATE TABLE将将表附加到此日志。CREATE SCHEMA创建一个包含QSQJRN等对象的库
  • 在库上使用适当的选项运行了STRJRNLIB命令。
英文:

The most common reason for SQL7008 is that the table is not journaled, but there are other reasons, and you are facing one. SQL7008, like many messages, gives more detail about the error and how to recover.

You probably have reason code 10
> 10 -- A constraint or trigger is being added to an invalid type of
> table, or the maximum number of triggers has been reached, or all
> nodes of the distributed table are not at the same release level.

You can create tables in QTEMP, but you can't add constraints (any type) or triggers to a table in QTEMP, so you can't create a table with a primary key. As a workaround to your case you can create a unique index in QTEMP that "constraints" your table.

There is two ways to tell in which schema the table have to be created using SQL, in RUNSQLSTM or any other tool :

  • qualifying the name like you do with QTEMP
  • setting current schema

But telling where it has to be created is not enough.
No object can be journaled in QTEMP, that's true but in other schemas, tables can be journaled automatically when created usingh SQL under conditions that QGPL does not fill :

  • There is a journal named QSQJRN in the library, CREATE TABLE will attach the table to this journal. CREATE SCHEMA creates a library that contains a journal name QSQJRN among other objects
  • Command STRJRNLIB has been run on the library with the appropriate options.

huangapple
  • 本文由 发表于 2023年8月10日 11:56:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76872562.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定