Solved

Trigger UPDATE from 'inserted'

Posted on 2012-03-16
2
258 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
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
In this article I will describe the Copy Database Wizard 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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now