473,395 Members | 1,677 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.

MS SQL Trigger to update changes in a record

Yas
Hello All,

I have 2 tables in a MS SQL DB. Table1 and Table2.Log

Table2.Log was a copy of Table1 + an extra column for date_deleted. I
have 2 Triggers on Table1, Insert and delete. So when a record is
inserted into Table1 it's copied onto Table2.log, and when deleted in
Table1 the same record in Table2.log is time stamped with time of
deletion.

I would like to have another Trigger on Table1 for update. So if a
certain field (not primary key) is updated for a record it is also
updated in Table2.log This way Table2.log will always have exactly the
same fields per record as Table1.

I'm not sure how to reference the modified records only and update
just the modified fields...something like...?
----------------------------
CREATE TRIGGER [tr_updateT_Log] ON [dbo].Table1
FOR UPDATE
AS
Update Table2.Log
SET description = , office =
-------------------------------------------------
Any help would be greatly appreciated

Thanks
Y
Mar 11 '08 #1
2 7886
Yas wrote:
I would like to have another Trigger on Table1 for update. So if a
certain field (not primary key) is updated for a record it is also
updated in Table2.log This way Table2.log will always have exactly the
same fields per record as Table1.
Update triggers can reference both the 'inserted' and 'deleted'
pseudo-tables (IIRC the first contains the changed rows in their
post-change state, the second contains them in their pre- state).
Mar 12 '08 #2
Yas
On 12 Mar, 08:10, Ed Murphy <emurph...@socal.rr.comwrote:
Yas wrote:
I would like to have another Trigger on Table1 for update. So if a
certain field (not primary key) is updated for a record it is also
updated in Table2.log This way Table2.log will always have exactly the
same fields per record as Table1.

Update triggers can reference both the 'inserted' and 'deleted'
pseudo-tables (IIRC the first contains the changed rows in their
post-change state, the second contains them in their pre- state).
Is it possible to just update the columns in a row that have been
modified and leave the others untouched?

Thanks again
Mar 13 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Trevor Fairchild | last post by:
I am trying to create a very minimal auditing system for a series of databases. I am in the process of writing Update triggers for 5 Tablse. I will write a trigger for each table-the trigger's...
10
by: Lauren Quantrell | last post by:
I have never written a trigger before and now am seeing the light. Is there a way to write a trigger so that if a user changes any column in a single row on one table then the trigger will write...
3
by: takilroy | last post by:
Hi, Does anyone know of a simple way to do this? I want to create an insert trigger for a table and if the record already exists based on some criteria, I want to update the table with the...
5
by: keith.culpepper | last post by:
Can anyone please provide some assistance with a trigger that I need to develop. Here is the situation: Our program updates depend on database updates. If a client receives the program update...
1
by: rdraider | last post by:
Hi all, I know squat about triggers so was hoping somebody could point me in the right direction. I wanted to copy an email address field from a salesman table to a note field in a customer...
8
by: Benzine | last post by:
Hi, I have an issue with my replication at the moment. I will try to describe the scenario accurately. I am using MS SQL 2000 SP4 with Merge Replication. Subscribers connect to the publisher...
3
by: jdprime | last post by:
Hi, I am trying to write a trigger that will run when someone updates the delivery charge within the specified table. It will work, but will only record one change to the table. My question is, if...
0
by: magnolia | last post by:
i created a trigger that will record the changes made to a table .everything works fine except the insert query.whenerever i try to insert a record it fires insert and update triger at the same time...
2
by: Mike Stenzler | last post by:
Sorry- left out the complete error info: when I attempt to execute from SQL+ I get the following 3 errors: ORA-01403: no data found ORA-06512: at "TEST.AUROW_GRID_CLONE", line 8 ORA-04088:...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
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
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,...
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...

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.