Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Iron Speed
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old February 19th, 2008, 06:42 PM
cornelious cornelious is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 2 cornelious User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 m 29 sec
Reputation Power: 0
Help with Triggers

I am currently a student at a University in a SQL class with an assignment that has been very difficult in doing.

What I am assigned to do is create in essence two triggers. The first trigger is for Insert and is to set a particular column, CTL_REC_STAT, to 'A' and another column, CTL_INS_DTTM, to the current Date/Time.

The second trigger is for Update and is to set a the column CTL_REC_STAT to 'U' and CTL_UPD_DTTM to the current Date/Time whenever a record is updated.

The problem I am running into is that I currently use Update in my Insert trigger and as soon as the trigger executes the Update command it causes my Update trigger to execute. So even if I am Inserting something into the database the Update trigger executes and sets the CTL_REC_STAT to 'U' when it should be 'A'.

What do I need to do change to fix this issue.

This is my code:

CREATE TRIGGER [cis48315].[ONINSERT]
ON [cis48315].[APPLICATION_USERS]

FOR INSERT
AS

BEGIN

UPDATE APPLICATION_USERS
SET CTL_REC_STAT = 'A'
WHERE APP_USER_ID = APP_USER_ID

END

BEGIN

UPDATE APPLICATION_USERS
SET CTL_INS_DTTM = GETDATE()
WHERE APP_USER_ID = APP_USER_ID

END

and

CREATE TRIGGER [cis48315].[ONUPDATE]
ON [cis48315].[APPLICATION_USERS]

FOR UPDATE
AS

BEGIN

UPDATE APPLICATION_USERS
SET CTL_REC_STAT = 'U'
WHERE APP_USER_ID = APP_USER_ID

END

BEGIN

UPDATE APPLICATION_USERS
SET CTL_UPD_DTTM = GETDATE()
WHERE APP_USER_ID = APP_USER_ID

END

Thanks for the help.

Reply With Quote
  #2  
Old February 19th, 2008, 10:36 PM
cornelious cornelious is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 2 cornelious User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 m 29 sec
Reputation Power: 0
Just a little bump for some help

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > Help with Triggers


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

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

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

Iron Speed




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