Solved

Trigger UPDATE from 'inserted'

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
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 …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

19 Experts available now in Live!

Get 1:1 Help Now