IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Check number of deleted records in DSNTIAUL


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Rishi Trehan

New User


Joined: 14 Feb 2012
Posts: 5
Location: USA

PostPosted: Thu Feb 23, 2012 9:34 pm
Reply with quote

A team member accidentally deleted all records from a table using DSNTIAUL. I wish to prevent this in future. So far I have tried to use -

SOLUTION 1 -
DELETE FROM tablename
WHERE key IN ( SELECT key FROM tablename
WHERE key = 0002000100
FETCH FIRST 3 ROWS ONLY );

but I got an error -
DSNT408I SQLCODE = -4700, ERROR: ATTEMPT TO USE NEW FUNCTION BEFORE NEW
FUNCTION MODE

Looks like although we have DB2 V9, it is still not in New Function Mode.

SOLUTION 2 - Creating a view -
CREATE VIEW view1 AS
SELECT key, ROW_NUMBER() OVER (PARTITION BY key) RN
FROM tablename;
SELECT FROM view1
WHERE key = 0002000100
AND RN=3;

But I get an error -
SQL0104N An unexpected token "(" was found following "". Expected tokens may include: ", FROM INTO". SQLSTATE=42601
----------------------------------------------------------------------------------

I am fancying that there could be a way to check the value of SQLERRD(3) after the execution of the Delete statement. If the count is not what you expect then issue a Rollback.

Any ideas?

Regards
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Fri Feb 24, 2012 8:58 am
Reply with quote

Hi Rishi..

What is your exact requirement? How may records you want to delete?

You can use SQLERRD(3) to check how may no of records deleted in COBOL but I am not sure about DSNTIAUL.

Also your Subquery from Solution 1 will always return key 0002000100 as it is in where clause and in turn it will delete all records from table with key =0002000100.

How are you going to prevent deleting of records by creatinga VIEW?

Plase elaborate your requirement.

Regards,
Chandan
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Fri Feb 24, 2012 11:03 am
Reply with quote

chandan.inst wrote:

What is your exact requirement? How may records you want to delete?

How about reading and UNDERSTANDING the very first line of the topic. Read EVERY word. Then go away and blush and come back and say 'Ooops'.
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Fri Feb 24, 2012 12:07 pm
Reply with quote

Hi Nic,

I read the thread and understood the requirement.

I asked for the exact requirement after going through the below solution provided

SOLUTION 1 -
Code:
DELETE FROM tablename
WHERE key IN ( SELECT key FROM tablename
WHERE key = 0002000100
FETCH FIRST 3 ROWS ONLY );


With this all rows with key = 0002000100 will be deleted but subquery selects only first 3 rows

So I guess requirement is to delete only 3 rows which is not happening.

So just wanted to confirm the assumption what is the basic criteria for deleting the records

Regards,
Chandan
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Fri Feb 24, 2012 7:20 pm
Reply with quote

The requirement is to stop someone from accidentally deleteing ALL rows in the table as has happened.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts To fetch records that has Ttamp value... DFSORT/ICETOOL 4
No new posts ICETOOL returns no records JCL & VSAM 1
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts DSNTIAUL driven delete IBM Tools 0
Search our Forums:

Back to Top