473,614 Members | 2,321 Online
Bytes | Software Development & Data Engineering Community
+ 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=g etdate()
where order_id=@order id
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 2418
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=g etdate()
where order_id=@order id
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,c urdate) <= 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,c urdate) <= 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...her e'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...her e'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_IDENTIFI ER 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=g etdate()
where order_id=@order id
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_IDENTIFI ER 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=g etdate()
where order_id=@order id
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
1999
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 the SP will be finished ASAP, that's why, I do not want, and I do not need to wait for a trigger.
6
6545
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 to: SELECT * FROM INSERTED
9
3455
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, VARCHAR(10) WO.PROBLEMCODE, VARCHAR(8)
6
7135
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 the triggers are fired, various other operations are performed on other tables in the database. The triggers are not created on these other tables because other programs perform updates to these tables and we do not want the triggers to fire...
0
7135
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 TRIGGER statement.) I've also defined a SQL stored proc, and the trigger is set to call this SP. I've posted the simplified source below. I can manually call the stored proc, and the external trigger is created without any errors. However, when I do...
0
2467
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 I've found it educational. Note: - I build this for use in a JDEdwards OneWorld environment. I'm not sure how generic others find it but it should be fairly generic. - I use a C stored procedure GETJOBNAME to get some extra audit data,
1
2204
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 ROW
9
9306
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, with the exception of the table name. I could manually change the table name in the trigger and create it, over and over, but I'd like to automate this - by iterating through the collection of tables and passing the tablename to something that...
7
3295
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 following trigger create trigger chk_team on teams for insert as declare @chkCountry as char(2)
11
7863
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' does not exist drop table log_errors_tab;
0
8197
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8142
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8640
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8589
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8287
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8443
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6093
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5548
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2573
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 we have to send another system

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.