473,490 Members | 2,635 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Trigger

3 New Member
I have a table which takes order called ORDER

I need to create a update trigger which fires when a user X makes a transaction else ignore and continue and sleep for n seconds

for update
as
declare @lastuu varchar(6)
declare @orderid decimal(10)
select @lastuu = [last_upd_user] FROM INSERTED
select @orderid = [order_id] FROM INSERTED
if @lastuu='TM_DEV' -- check user value on for Transaction
begin
Update TS_ORDER
set last_upd_date=getdate()
where order_id=@orderid
end

How do I create a timer?
develop a timer on this and/or a method of updating only when the time is every n seconds
Aug 31 '07 #1
5 2414
ck9663
2,878 Recognized Expert Specialist
I have a table which takes order called ORDER

I need to create a update trigger which fires when a user X makes a transaction else ignore and continue and sleep for n seconds

for update
as
declare @lastuu varchar(6)
declare @orderid decimal(10)
select @lastuu = [last_upd_user] FROM INSERTED
select @orderid = [order_id] FROM INSERTED
if @lastuu='TM_DEV' -- check user value on for Transaction
begin
Update TS_ORDER
set last_upd_date=getdate()
where order_id=@orderid
end

How do I create a timer?
develop a timer on this and/or a method of updating only when the time is every n seconds
do a loop until you reach the amount of times you want to sleep

curdate = getdate()

while dateadd(ss,10,curdate) <= getdate()
continue


be careful and avoid endless loop


or try waitfor delay
Aug 31 '07 #2
arracathce
3 New Member
do a loop until you reach the amount of times you want to sleep

curdate = getdate()

while dateadd(ss,10,curdate) <= getdate()
continue


be careful and avoid endless loop


or try waitfor delay

Can you maybe give me a example since getdate() is always sysdate so I ma confused that this will always continues
Sep 3 '07 #3
ck9663
2,878 Recognized Expert Specialist
Can you maybe give me a example since getdate() is always sysdate so I ma confused that this will always continues

sorry about that...that's just an algorithm...here's a 3-second timer...

Expand|Select|Wrap|Line Numbers
  1. select 'start:' + cast(getdate() as varchar(15))
  2.  
  3. BEGIN
  4.     WAITFOR DELAY '00:00:3'
  5.     select 'end:' + cast(getdate() as varchar(15))
  6. END
  7. GO
  8.  
Sep 3 '07 #4
arracathce
3 New Member
sorry about that...that's just an algorithm...here's a 3-second timer...

Expand|Select|Wrap|Line Numbers
  1. select 'start:' + cast(getdate() as varchar(15))
  2.  
  3. BEGIN
  4.     WAITFOR DELAY '00:00:3'
  5.     select 'end:' + cast(getdate() as varchar(15))
  6. END
  7. GO
  8.  

One other thing if I want this trigger to fire and only do an update when the user is not BLA can i just change the statement to read

set ANSI_NULLS ON
set QUOTED_IDENTIFIER OFF
GO
ALTER trigger [dbo].[TS_ORDER_UPD]
on [dbo].[TS_ORDER]
for update
as
declare @lastuu varchar(6)
declare @orderid decimal(10)
select @lastuu = [last_upd_user] FROM INSERTED
select @orderid = [order_id] FROM INSERTED
if @lastuu !='BLA' -- SO only execute update and change time when user is not BLA
begin
Update TS_ORDER
set last_upd_date=getdate()
where order_id=@orderid
end
Sep 4 '07 #5
ck9663
2,878 Recognized Expert Specialist
One other thing if I want this trigger to fire and only do an update when the user is not BLA can i just change the statement to read

set ANSI_NULLS ON
set QUOTED_IDENTIFIER OFF
GO
ALTER trigger [dbo].[TS_ORDER_UPD]
on [dbo].[TS_ORDER]
for update
as
declare @lastuu varchar(6)
declare @orderid decimal(10)
select @lastuu = [last_upd_user] FROM INSERTED
select @orderid = [order_id] FROM INSERTED
if @lastuu !='BLA' -- SO only execute update and change time when user is not BLA
begin
Update TS_ORDER
set last_upd_date=getdate()
where order_id=@orderid
end
if you're storing the username on that field, yes. or you may also check the value of SYSTEM_USER system variable. it returns the current username used to connect to the sql server
Sep 5 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1990
by: Matik | last post by:
Hello to all, I have a small question. I call the SP outer the DB. The procedure deletes some record in table T1. The table T1 has a trigger after delete. This is very importand for me, that...
6
6530
by: Scott CM | last post by:
I have a multi-part question regarding trigger performance. First of all, is there performance gain from issuing the following within a trigger: SELECT PrimaryKeyColumn FROM INSERTED opposed...
9
3447
by: Martin | last post by:
Hello, I'm new with triggers and I can not find any good example on how to do the following: I have two tables WO and PM with the following fields: WO.WONUM, VARCHAR(10) WO.PMNUM,...
6
7116
by: Mary | last post by:
We are developing a DB2 V7 z/OS application which uses a "trigger" table containing numerous triggers - each of which is activated by an UPDATE to a different column of this "trigger" table. When...
0
7125
by: Dave Sisk | last post by:
I've created a system or external trigger on an AS/400 file a.k.a DB2 table. (Note this is an external trigger defined with the ADDPFTRG CL command, not a SQL trigger defined with the CREATE...
0
2445
by: JohnO | last post by:
Thanks to Serge and MarkB for recent tips and suggestions. Ive rolled together a few stored procedures to assist with creating audit triggers automagically. Hope someone finds this as useful as...
1
2191
by: deepdata | last post by:
Hi, I am creating a trigger in DB2 express version. When i use the following syntax to create trigger CREATE TRIGGER USER_PK_TRIGGER BEFORE INSERT On users REFERENCING NEW As N FOR EACH...
9
9295
by: Ots | last post by:
I'm using SQL 2000, which is integrated with a VB.NET 2003 app. I have an Audit trigger that logs changes to tables. I want to apply this trigger to many different tables. It's the same trigger,...
7
3272
by: Shane | last post by:
I have been instructed to write a trigger that effectively acts as a foreign key. The point (I think) is to get me used to writing triggers that dont use the primary key(s) I have created the...
11
7841
by: tracy | last post by:
Hi, I really need help. I run this script and error message appeal as below: drop trigger log_errors_trig; drop trigger log_errors_trig ERROR at line 1: ORA04080: trigger 'LOG_ERRORS-TRIG'...
0
7112
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7183
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7356
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5448
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4573
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
628
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
277
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.