If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > How to delete data using automatic approach

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-02-06, 14:05
palchuri palchuri is offline
Registered User
 
Join Date: Jan 2003
Posts: 47
How to delete data using automatic approach

I have a table called fm_rel having the following columns
id,creationtime. Every day we add entries to this table. I need the logic(database trigger) which will identify any record which is older than 7 days and delete the record.

Can I write a trigger which can identify the age with out doing any manipulations on the record.

I am not sure it is feasible also , any ideas will be appreciated.


Shri
__________________
p.srinivasarao
Reply With Quote
  #2 (permalink)  
Old 02-02-06, 15:37
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 554
How about something like

delete from fm_rel where creationtime < current date -7 days
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
Reply With Quote
  #3 (permalink)  
Old 02-02-06, 16:54
palchuri palchuri is offline
Registered User
 
Join Date: Jan 2003
Posts: 47
To perform this I should have a process runs everyday. Can we write a intellegent trigger(I don't trigger supports this... some way) which automatically identifies n days older data and delete it automatically. Any ideas?



Quote:
Originally Posted by palchuri
I have a table called fm_rel having the following columns
id,creationtime. Every day we add entries to this table. I need the logic(database trigger) which will identify any record which is older than 7 days and delete the record.

Can I write a trigger which can identify the age with out doing any manipulations on the record.

I am not sure it is feasible also , any ideas will be appreciated.


Shri
__________________
p.srinivasarao
Reply With Quote
  #4 (permalink)  
Old 02-03-06, 01:25
JAYANTA_DATTA JAYANTA_DATTA is offline
Registered User
 
Join Date: Oct 2004
Location: DELHI INDIA
Posts: 336
Quote:
Originally Posted by palchuri
To perform this I should have a process runs everyday. Can we write a intellegent trigger(I don't trigger supports this... some way) which automatically identifies n days older data and delete it automatically. Any ideas?
Once a trigger is written, its ready for execution always. Make some condition like On INSERT/UPDATE, i mean whenever there will be some action on the source table then the TRIGGER will be FIRED.
See the Syntax of Triggers for better understanding.

Thanks,
Jay
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On