Ibm midrange 系统周期时态表和外键。。。关于删除级联

Ibm midrange 系统周期时态表和外键。。。关于删除级联,ibm-midrange,db2-400,Ibm Midrange,Db2 400,尝试添加外键时出错。。。在删除级联时对a的约束-在我下面的示例中是状态表 我可以让应用程序层进行清理,但我更愿意让数据库自己处理内部事务 父表: 0001.00 -- ************************************************************************************************* 0002.00 -- Create the table.

尝试添加
外键时出错。。。在删除级联时
对a的约束-在我下面的示例中是
状态

我可以让应用程序层进行清理,但我更愿意让数据库自己处理内部事务

父表:

0001.00 -- *************************************************************************************************
0002.00 -- Create the table.                                                                                
0003.00 -- *************************************************************************************************
0004.00 CREATE OR REPLACE TABLE country (                                                                   
0005.00   iso2   CHAR(2) NOT NULL,                                                                          
0006.00   iso3   CHAR(3) NOT NULL,                                                                          
0007.00   isonum CHAR(3) NOT NULL,                                                                          
0008.00   name   VARCHAR(45) NOT NULL,                                                                      
0009.00   sys_start                                                                                         
0010.00     TIMESTAMP(12) NOT NULL GENERATED ALWAYS AS ROW BEGIN IMPLICITLY HIDDEN,                         
0011.00   sys_end                                                                                           
0012.00     TIMESTAMP(12) NOT NULL GENERATED ALWAYS AS ROW END IMPLICITLY HIDDEN,                           
0013.00   sys_ts                                                                                            
0014.00     TIMESTAMP(12) NOT NULL GENERATED ALWAYS AS TRANSACTION START ID                                 
0015.00     IMPLICITLY HIDDEN,                                                                              
0016.00   PERIOD SYSTEM_TIME(sys_start, sys_end),                                                           
0017.00   PRIMARY KEY(iso2)                                                                                 
0018.00 ) RCDFMT rcountry;                                                                                  
0019.00                                                                                                     
0020.00 COMMIT;                                                                                             
0021.00                                                                                                     
0022.00 -- *************************************************************************************************
0023.00 -- Create a history table to track all changes.                                                     
0024.00 -- *************************************************************************************************
0025.00 CREATE OR REPLACE TABLE countryh LIKE country;                                                      
0026.00                                                                                                     
0027.00 COMMIT;                                                                                             
0028.00                                                                                                     
0029.00 -- *************************************************************************************************
0030.00 -- Associate our history table with the main table and tell the system to add a row to the history  
0031.00 -- table when a row is deleted so we'll have a record of the deletion.                              
0032.00 -- *************************************************************************************************
0033.00 ALTER TABLE country ADD VERSIONING USE HISTORY TABLE countryh                                       
0034.00   ON DELETE ADD EXTRA ROW;                                                                          
0035.00                                                                                                     
0036.00 COMMIT;                                                                                             
子表:

0001.00 -- *************************************************************************************************
0002.00 -- Create the table.                                                                                
0003.00 -- ****************************************************************************|********************
0004.00 CREATE OR REPLACE TABLE state (                                                                     
0005.00   id BIGINT GENERATED ALWAYS AS IDENTITY (START WITH 1 CYCLE),                                      
0006.00   cntry_id CHAR(2) NOT NULL,                                                                        
0007.00   code     VARCHAR(3) NOT NULL,                                                                     
0008.00   name     VARCHAR(35) NOT NULL,                                                                    
0009.00   sys_start                                                                                         
0010.00     TIMESTAMP(12) NOT NULL GENERATED ALWAYS AS ROW BEGIN IMPLICITLY HIDDEN,                         
0011.00   sys_end                                                                                           
0012.00     TIMESTAMP(12) NOT NULL GENERATED ALWAYS AS ROW END IMPLICITLY HIDDEN,                           
0013.00   sys_ts                                                                                            
0014.00     TIMESTAMP(12) NOT NULL GENERATED ALWAYS AS TRANSACTION START ID                                 
0015.00     IMPLICITLY HIDDEN,                                                                              
0016.00   PERIOD SYSTEM_TIME(sys_start, sys_end),                                                           
0017.00   PRIMARY KEY(id),                                                                                  
0018.00   UNIQUE (cntry_id, code)                                                                           
0019.00 ) RCDFMT rstate;                                                                                    
0020.00                                                                                                     
0021.00 COMMIT;                                                                                             
0022.00                                                                                                     
0023.00 -- *************************************************************************************************
0024.00 -- Create a history table to track all changes.                                                     
0025.00 -- *************************************************************************************************
0026.00 CREATE OR REPLACE TABLE stateh LIKE state;                                                          
0027.00                                                                                                     
0028.00 COMMIT;                                                                                             
0029.00                                                                                                     
0030.00 -- *************************************************************************************************
0031.00 -- Associate our history table with the main table and tell the system to add a row to the history  
0032.00 -- table when a row is deleted so we'll have a record of the deletion.                              
0033.00 -- *************************************************************************************************
0034.00 ALTER TABLE state ADD VERSIONING USE HISTORY TABLE stateh                                           
0035.00   ON DELETE ADD EXTRA ROW;                                                                          
0036.00                                                                                                     
0037.00 COMMIT;                                                                                             
0038.00                                                                                                     
0039.00 ALTER TABLE state ADD FOREIGN KEY(cntry_id) REFERENCES country(iso2)                                
0040.00   ON DELETE CASCADE;
0041.00                     
0042.00 COMMIT;             
我的编译列表中显示的是:

MSG ID  SEV  RECORD  TEXT
SQ20525  30      39  Position 1 Operation on table STATE in HILLB1 not
                     allowed.                                         
我的作业日志中显示的错误是:

Constraint is not valid.
当我执行F1提示以获得更多信息时:

Message . . . . :   Constraint is not valid.                                 
Cause . . . . . :   Constraint *N cannot be added for file STATE in library  
  HILLB1 for TYPE value *N. For a referential constraint (TYPE *REFCST), the 
  parent file *N in library *N has a delete rule of *N and update rule of *N.
  The constraint was not added because of errors. The reason code is 6. The  
  reason codes and their meanings are as follows:                            
    06 - The file is a system-period temporal table and the referential    
  constraint cannot use the delete rule of *CASCADE, *SETDFT, and *SETNULL.
很明显,他不喜欢我想做的事

我还尝试将
外键
定义放在
CREATE或REPLACE TABLE
语句中,得到了相同的错误(尽管是在第34行)


当父表删除一行时,真的没有办法让依赖表(即系统周期时态表)删除相关行吗?

您尝试过删除触发器吗?@jmarkmurphy-事实上,删除触发器是有效的。如果你把它写下来作为答案,我会投赞成票并接受它。谢谢你试过删除触发器吗?@jmarkmurphy-事实上,删除触发器是有效的。如果你把它写下来作为答案,我会投赞成票并接受它。谢谢