Question : delete records in a table which has master - detail relationship with another.

Hello Experts,

I have two tables --- informix_eod_train_participnt A (rowcount -305,219 )
                             ---informix_eod_train_act B (rowcount 35084)
The B table has a unique column activity_nbr which has 35084 unique records.
And the A table is like detail oriented table, and gets joined by activity_nbr
For every activity_nbr in Table B(lets say 100) there will be 5 or 6 records in the Table A.

So, I have used some records retention schedule and deleted about 120, 000 records in Table A, so now the
                        rowcount for Table A -- 180, 219

How do I delete the corresponding records in Table A. It initially has 35, 000 records but I am expecting that based on table A It will atleast have 10,000 records deleted.

Could you please let me know how to achieve this.

structure of the tables are below:
Table A  -- Detail table
CREATE TABLE ETS.MCL_EOD_TRAIN_PARTICIPNT    
(
  TRN_ACTIVITY_KEY  VARCHAR2(10 BYTE),
  EMPE_SSN           VARCHAR2(10 BYTE),
  NOMINATION_DATE    VARCHAR2(20 BYTE),
  CONFIRMATION_DATE  VARCHAR2(20 BYTE),
  VERIFICATION_DATE  VARCHAR2(20 BYTE),
  DTTM_CREATED       VARCHAR2(20 BYTE),
  OPER_INIT_NBR      VARCHAR2(15 BYTE),
  DTTM_UPDATED       VARCHAR2(20 BYTE),
  OPER_UPDATE_NBR    VARCHAR2(15 BYTE)
);

Table B ----Master
CREATE TABLE ETS.INFORMIX_EOD_TRAIN_ACT
(
  ACTIVITY_NBR       VARCHAR2(10 BYTE),
  LOCATION_CODE      VARCHAR2(10 BYTE),
  TRN_EVENT          VARCHAR2(10 BYTE),
  TRN_CATEGORY_NBR   VARCHAR2(10 BYTE),
  TRN_SUB_CATEGORY   VARCHAR2(10 BYTE),
  TRN_SEQUENCE_NO    VARCHAR2(10 BYTE),
  TRN_NBR_OF_HRS     VARCHAR2(10 BYTE),
  MAX_PARTICIPANTS   VARCHAR2(10 BYTE),
  TRN_START_DATE     VARCHAR2(20 BYTE),
  TRN_END_DATE       VARCHAR2(20 BYTE),
  STATE_ABBREV       VARCHAR2(20 BYTE),
  CITY_NBR           VARCHAR2(20 BYTE),
  DATE_INACTIVE      VARCHAR2(20 BYTE),
  TRN_ACTIVITY_DESC  VARCHAR2(100 BYTE),
  ACTIVITY_COMMENT   CLOB,
  DTTM_CREATED       VARCHAR2(20 BYTE),
  OPER_INIT_NBR      VARCHAR2(15 BYTE),
  DTTM_UPDATED       VARCHAR2(20 BYTE),
  OPER_UPDATE_NBR    VARCHAR2(15 BYTE)
)

Answer : delete records in a table which has master - detail relationship with another.

>>Does it generally take long time to delete those records

This is system specific.

Did you add the index before or after you started the delete?

You might be able to speed things ip a little with a PL/SQL loop and batched commits.

something like (typed in, might have syntax errors):

declare
   myCount number :=1;
begin
for i in (select id from detail) loop
delete from master where id=id;

--commit every 1000 rows
if mod(myCount,1000)=0 then
commit;
end if;
myCount := myCount + 1;
end loop;
end;
/
Random Solutions  
 
programming4us programming4us