Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

To maintain Audit log for Employee table

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
karthi_ind

Active User


Joined: 24 Feb 2004
Posts: 131
Location: Chennai

PostPosted: Wed Mar 10, 2010 11:59 am    Post subject: To maintain Audit log for Employee table
Reply with quote

I have one table called Employee and detail would like below

EMP_TABLE
S.No Emp_Id EmP_Name Emp_Salary
1 123 John 100
5 123 Sunil 100
7 123 Raj 500
10 123 Joseph 101

When ever i do the update on the columns like Emp_Name or Emp_Salary a new record is inserted into the same table with new S.No
For Ex. Emp_Name "John" Changed to "Sunil" new record is inserted into the table with S.No"5".

Note:Emp_ID will remain same and it can't be changed/updated.

Now My requirement is "I should generate the report(using Cursors in SQL Stored procedure) for audit log" for the "employee_Id 123" The report should be like below

Changed Field Old Value New value
Employee Name John Sunil
Employee Name Sunil Raj
Employee Nmae Raj Joseph
Employee Salary 100 500
Employee Salary 500 101
Back to top
View user's profile Send private message

GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Wed Mar 10, 2010 4:37 pm    Post subject:
Reply with quote

well, good luck with that. It won't be easy.
Back to top
View user's profile Send private message
sushanth bobby

Senior Member


Joined: 29 Jul 2008
Posts: 1013
Location: India

PostPosted: Wed Mar 10, 2010 5:03 pm    Post subject:
Reply with quote

Karthi,

You got to be kidding me !
Quote:
a new record is inserted into the same table with new S.No

Single table holding employee records & audit records as well. Did normalization went for a vacation or what ?

Sushanth
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Wed Mar 10, 2010 5:10 pm    Post subject:
Reply with quote

True - you should have been using another table for audit with a trigger on the base table.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Wed Mar 10, 2010 9:26 pm    Post subject:
Reply with quote

Hello,

I suspect this is the audit table. . . I may misunderstand, but i believe the requirement is to show all of the before/after values when there have been modifications.

Possibly Karthi will clarify. . .
Back to top
View user's profile Send private message
karthi_ind

Active User


Joined: 24 Feb 2004
Posts: 131
Location: Chennai

PostPosted: Thu Mar 11, 2010 12:26 pm    Post subject: Reply to: To maintain Audit log for Employee table
Reply with quote

Hi all,

Thanks for your reply.

Basically what I want is the report kind of thing which tells about what are all the changes done in the table. Like empname has been changed to new name, salary has been changed to new one. This needs to be done using sql query in stored procedure.

Sushanth,

The table contains multiple records and I want only the changes done for name and salary. so I dont think normalization comes into picture on this.

Please clarify.

Thanks.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Thu Mar 11, 2010 1:56 pm    Post subject:
Reply with quote

You could use this as starting point :
Code:
select old.id, old.no, old.name, old.sal, new.no,new.name, new.sal
from EMP_TABLE old
      , EMP_TABLE new
where old.id = new.id
  and (   old.Name = new.name
       or old.sal  = newt.Sal)
  and new.no = (select min(no) from EMP_table nxt
                 where old.id = nxt.id
                   and nxt.no > old.no
                )
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Thu Mar 11, 2010 4:38 pm    Post subject:
Reply with quote

in previous post, ofcourse it must be

(old.name <> new.name or old.sal <> new.sal)
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Loading data to table gives wrong for... Raghu navaikulam DB2 18 Thu Jul 13, 2017 2:11 pm
No new posts unload data from table with lob columns farhad_evan DB2 1 Sat Apr 22, 2017 1:32 pm
No new posts Data replication from multiple Db2 ta... kishpra DB2 9 Mon Mar 27, 2017 9:58 pm
No new posts how to send just 10 rows in a CICS sc... Megha Gupta CICS 5 Thu Feb 23, 2017 6:57 pm
No new posts Join of more than one table dibyendumandal11111 DB2 6 Mon Feb 13, 2017 11:36 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us