473,411 Members | 1,894 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,411 software developers and data experts.

database wide trigger firing with update

hi all,

i want to do something like that; if someone tries to update a table, the trigger will fire and add a new record that contains the field name, old value and new value.

i have already done a small part of it.

the code is below.

Expand|Select|Wrap|Line Numbers
  1. set ANSI_NULLS ON 
  2. set QUOTED_IDENTIFIER ON 
  3. GO 
  4. ALTER TRIGGER [dbo].[forumchange] ON test2 
  5. FOR UPDATE 
  6. AS 
  7. BEGIN 
  8. Declare @newNAME varchar(64) 
  9. Declare @oldNAME varchar(64) 
  10. declare @date datetime 
  11. Select @oldNAME = ad from deleted 
  12. Select @newNAME = ad from inserted 
  13. select @date = getdate() 
  14. if (@newNAME is not null) and (@oldNAME is not null) 
  15. insert into test3 (oldNAME,newNAME,date) 
  16. values (@oldname,@newname,@date) 
  17. END
as you see, the trigger fires up with any update on test2 db.

but current code only controls the "name" field of the table name_surname.
i want it to go after every field and log them.

thank you.
Oct 22 '08 #1
1 1480
ck9663
2,878 Expert 2GB
Use UPDATE() to see if the column was updated. Then do the necessary update.

Happy coding!

-- CK
Oct 22 '08 #2

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

Similar topics

6
by: Rolf Kemper | last post by:
Dear All, we are running SQL2000 Sever and make use of the xp_sendmail. For any reason the mail service can run into problems and it looks like that the statemnt below gets not finished. ...
8
by: Remove the obvious for replies | last post by:
I am using DB2 8.1.4 with SDE and Info Integrator. I am trying to create a trigger to populate a spatial table based on values from an attribute table. However, it appears to not recognize the CASE...
2
by: Jack | last post by:
We are have a question about the no cascade option on before triggers. The description stays that no other triggers will be fired by the changes of a before trigger. One of our developers is...
2
by: Net Virtual Mailing Lists | last post by:
Hello, If I have a rule like this: CREATE OR REPLACE RULE sometable_update AS ON UPDATE TO table2 DO UPDATE cache SET updated_dt=NULL WHERE tablename='sometable'; CREATE OR REPLACE RULE...
1
by: aj70000 | last post by:
hi, Here's the scenario 1) I am running a DTS job to fetch some rows from Oracle 2) The job populates the Table A as step 1 3) Then it fires a update statement which updates the rows in Table...
1
by: abhi81 | last post by:
Hello All, I have a table on which I have created a insert,Update and a Delete trigger. All these triggers write a entry to another audit table with the unique key for each table and the timestamp....
5
by: danishahmed2007 | last post by:
i have a table of the format CREATE TABLE testing ( emp_name varchar(50), emp_id int, rec_up datetime DEFAULT (getdate()) ) and on the event of an update to any column in...
22
by: DreamersDelight | last post by:
Hi, I'm stuck on this problem and I can't find a sollution. I'm going to try and explain this step by step. 1 After certain rows get updated with a certain value. I don't know wich rows in...
3
by: | last post by:
Hi - I can update a second field based on update of the the first field of the same table. It works fine in the Enterprise Manager (EM), but I can't seem to make the trigger fire when I alter the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
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
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
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...

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.