Solved

Update timestamp with Trigger.

Posted on 2006-07-20
1
827 Views
Last Modified: 2008-01-09
I'm a MSSQL novice and I am trying to create a trigger that will copy data as it is inserted into the results table of one DB into a tblBReagleresult table in another DB. I have succeeded in copying the data, but I also want to insert the date and time that the record was updated also. Now I have the syntax listed below but it will modify the time on all records in that field. We are currently using MSSQL 7.0, here is the trigger I have.

CREATE TRIGGER [CopyResults] ON [dbo].[result]
FOR INSERT
AS
INSERT INTO [STOCKYARDS].[dbo].[tblBReagleresult]([ProdID], [Throughput], [OpNr], [ResultNr], [Val], [ValueID])
SELECT [ProdID], [Throughput], [OpNr], [ResultNr], [Val], [ValueID] FROM INSERTED
update [STOCKYARDS].[dbo].[tblBReagleresult]
set [transtime]=getdate()
0
Comment
Question by:power4350
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 25

Accepted Solution

by:
Mr_Peerapol earned 50 total points
ID: 17151443
CREATE TRIGGER [CopyResults] ON [dbo].[result]
FOR INSERT
AS
INSERT INTO [STOCKYARDS].[dbo].[tblBReagleresult]([ProdID], [Throughput], [OpNr], [ResultNr], [Val], [ValueID], [transtime])
SELECT [ProdID], [Throughput], [OpNr], [ResultNr], [Val], [ValueID], GETDATE() FROM INSERTED
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question