Solved

Trigger UPDATE from 'inserted'

Posted on 2012-03-16
2
263 Views
Last Modified: 2012-08-13
Hello,

I am trying to create a trigger which should monitor the table tbUsers. Once a record is inserted into tbUsers it should update the column of the table tbWatch 'LastLogged' with the current date/time from the server and also add the value of 1 to the column 'TimesLogged'. The table tbUsers and tbWatch connect on the column 'MAC' so obviously the update should happen only if the MAC value from the rows to be appended on tbUsers match those of tbWatch.

Many thanks
0
Comment
Question by:MissNicola
[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
2 Comments
 
LVL 42

Accepted Solution

by:
dqmq earned 500 total points
ID: 37731946
CREATE TRIGGER YourTrigger ON tbUsers
AFTER INSERT
AS
BEGIN
UPDATE tbWatch
set LastLogged=getdate()
,TimesLogged=TimesLogged+1
FROM tbWatch w inner join inserted i on i.mac = w.mac
END
0
 

Author Comment

by:MissNicola
ID: 37732521
That was excellent! Many thanks!!!!
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

717 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