|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
Just a little bump for some help
|
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft SQL Server > Help with Triggers |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|