Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 trigger 60 seconds after record is inserted

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2008-11-23 : 01:45:00
is it possible to run a trigger 60 seconds after a record is inserted and change a field called show=0

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-23 : 01:57:41
its better to schedule this as a sql job which fires after predefined period and sets show=0 for all records that were created before 60 seconds. you need to have an audit column like datecreated on table to distinguish recently created records for this.
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2008-11-23 : 02:05:09
will it tie down the sql to have this schedule every 3 seconds?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-23 : 02:34:49
quote:
Originally posted by esthera

will it tie down the sql to have this schedule every 3 seconds?


every 3 seconds? no need...since what you want is set value for bit field for records created since a minutes, any schedule more than a minute will be fine.
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2008-11-23 : 02:42:37
the issue is i have records constantly added and exactly 60 seconds after they are added i want them to change from show=1 to show=0
so i would need to be checking every second as they can always be added.
won't this tie down the server?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-23 : 02:52:42
quote:
Originally posted by esthera

the issue is i have records constantly added and exactly 60 seconds after they are added i want them to change from show=1 to show=0
so i would need to be checking every second as they can always be added.
won't this tie down the server?


yup that would have serious impact on server. can you explain why you want to do it exactly after 60 s?
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2008-11-23 : 02:56:15
basically i have a program that shows each record as it comes in but for just 60 seconds.
i'm not setting a timer and updating the sql but thought it would be better to do on the sql side.
You can't set a trigger off 60 seconds after a record is inserted?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-23 : 03:46:36
quote:
Originally posted by esthera

basically i have a program that shows each record as it comes in but for just 60 seconds.
i'm not setting a timer and updating the sql but thought it would be better to do on the sql side.
You can't set a trigger off 60 seconds after a record is inserted?


Thats not certainly a good approach.Cant you just handle this at front end rather than making the change in db?
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2008-11-23 : 03:50:46
i thought the db would be better - ok i'll keep a timer on the frontend for now - i just thought it would be more efficient if it was possible to do with a trigger.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-23 : 03:53:16
quote:
Originally posted by esthera

i thought the db would be better - ok i'll keep a timer on the frontend for now - i just thought it would be more efficient if it was possible to do with a trigger.


not at all..Use of trigger will certainly hurt performance.
Go to Top of Page
   

- Advertisement -