Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 18th, 2006, 11:49 AM
dcostelloe dcostelloe is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Location: Burlington, Ontario Canada
Posts: 10 dcostelloe User rank is Private First Class (20 - 50 Reputation Level)dcostelloe User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 h 4 m 39 sec
Reputation Power: 0
Send a message via MSN to dcostelloe
Wink Trigger or no Trigger

I have an Date field which I would like to have populated every time a record is inserted.

Is it best to do this in a trigger or via stored proc?

Trigger:
UPDATE GOOD_SAYINGS SET GOOD_DATE =CURRENT_TIMESTAMP WHERE ID = ' How to get the lastest ID as this is a after insert trigger';

I will need to get the latest ID field to add a where clause. How would be the best method for this?


Reply With Quote
  #2  
Old March 18th, 2006, 02:32 PM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,815 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 1 Day 14 m 37 sec
Reputation Power: 278
Is the trigger updating a field in the same table that is updated by the triggering sql statement?

Reply With Quote
  #3  
Old March 18th, 2006, 03:20 PM
dcostelloe dcostelloe is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Location: Burlington, Ontario Canada
Posts: 10 dcostelloe User rank is Private First Class (20 - 50 Reputation Level)dcostelloe User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 h 4 m 39 sec
Reputation Power: 0
Send a message via MSN to dcostelloe
Lightbulb

Quote:
Originally Posted by pabloj
Is the trigger updating a field in the same table that is updated by the triggering sql statement?


Not yet but could if the trigger is the way to go. I thinking of populating the date field after insert. I guess the answer would be yes as the trigger is updating the field is this a good idea?


Reply With Quote
  #4  
Old March 18th, 2006, 03:29 PM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,815 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 1 Day 14 m 37 sec
Reputation Power: 278
In this case you can use an "before update" or "before insert" trigger to set the new value for the column

Reply With Quote
  #5  
Old March 18th, 2006, 04:06 PM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,815 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 1 Day 14 m 37 sec
Reputation Power: 278
Trigger is the way to go!

See my blog for an example.

Last edited by pabloj : March 18th, 2006 at 04:10 PM.

Reply With Quote
  #6  
Old March 19th, 2006, 10:02 AM
dcostelloe dcostelloe is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Location: Burlington, Ontario Canada
Posts: 10 dcostelloe User rank is Private First Class (20 - 50 Reputation Level)dcostelloe User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 h 4 m 39 sec
Reputation Power: 0
Send a message via MSN to dcostelloe
Thumbs up

Quote:
Originally Posted by pabloj
Trigger is the way to go!

See my blog for an example.


Nice example thanks!


Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > Trigger or no Trigger


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway