473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Trigger

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 2412
ck9663
2,878 Expert 2GB
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
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 Expert 2GB
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
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 Expert 2GB
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
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
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
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
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
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
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
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
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
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
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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.