Login or Sign Up to become a member!
LessThanDot Site Logo

LessThanDot

A Technical Community for IT Professionals

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Highly Rated Users

Forum
No Posts Rated

Top 50
Given
Received

Links

Wiki
Blog

Forum Statistics

Users
Members:
1875
Members Online:
3
Guests Online:
42

Total Post History
Posts:
81447
Topics:
18714

7-Day Post History
New Posts:
0
New Topics:
0
Active Topics:
0

Our newest member
konam534As

Other

FAQ
All times are UTC [ DST ]

Google Ads

Updated trigger

Microsoft SQL Server
Please wait...

Updated trigger

Postby Remou on Mon Jun 30, 2014 4:23 pm

Would it be wrong to create such a trigger? I must admit I have not even tested, I would just like an opinion. Thank you.

  1. -- http://stackoverflow.com/questions/9522 ... ger-update
  2. CREATE TRIGGER dbo.Location_Updated
  3. ON dbo.Locations
  4. FOR UPDATE /* Fire this trigger when a row UPDATEd */
  5. AS BEGIN
  6.   UPDATE dbo.Locations SET
  7.      dbo.Locations.DateModified = CURRENT_TIMESTAMP
  8.     ,dbo.locations.ModifiedByname = CURRENT_USER
  9.   FROM INSERTED
  10.   WHERE inserted.id=dbo.Locations.id
  11. END
Stop quoting laws to us. We carry swords.
User avatar
Remou
LTD Admin
LTD Admin
LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971
LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971
LTD Gold - Rating: 971
 
Posts: 5414
Joined: Sun Oct 14, 2007 11:26 am
Unrated

Re: Updated trigger

Postby SQLDenis on Mon Jun 30, 2014 5:35 pm

Is that valid syntax? Don't you need dbo.Locations in the FROM as well?
User avatar
SQLDenis
LTD Admin
LTD Admin
LTD Gold - Rating: 3467LTD Gold - Rating: 3467LTD Gold - Rating: 3467LTD Gold - Rating: 3467LTD Gold - Rating: 3467
LTD Gold - Rating: 3467LTD Gold - Rating: 3467LTD Gold - Rating: 3467LTD Gold - Rating: 3467LTD Gold - Rating: 3467
LTD Gold - Rating: 3467LTD Gold - Rating: 3467LTD Gold - Rating: 3467
 
Posts: 21784
Joined: Wed Oct 10, 2007 6:43 pm
Location: Princeton, New Jersey, USA,World, Solar System, Milky Way, Universe and Beyond
Unrated

Re: Updated trigger

Postby Remou on Mon Jun 30, 2014 5:45 pm

SQLDenis wrote:Is that valid syntax? Don't you need dbo.Locations in the FROM as well?


I eventually tested, and it seemed to work okay. I even ended up with what I wanted in the updated fields. I was worrying if it was a bad idea to use these kinds of triggers.
Stop quoting laws to us. We carry swords.
User avatar
Remou
LTD Admin
LTD Admin
LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971
LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971LTD Gold - Rating: 971
LTD Gold - Rating: 971
 
Posts: 5414
Joined: Sun Oct 14, 2007 11:26 am
Unrated

Re: Updated trigger

Postby SQLSister on Tue Jul 08, 2014 7:39 pm

That's the kind of thing triggers are needed for. A constraint can populate on insert but the only way to get these tyypes of field s proerly updated anytime the record is updated is through a triggier. There are folks who think the App can just send the code but then you won't get the code changes from outside the aplications including any possible malicious ones (especially those from people inside the company, devs forget they have to protect from disgruntled employees too).
SQLSister
LTD Senior Moderator
LTD Senior Moderator
LTD Bronze - Rating: 189LTD Bronze - Rating: 189LTD Bronze - Rating: 189LTD Bronze - Rating: 189
 
Posts: 704
Joined: Wed Jun 04, 2008 10:43 pm
Location: Virginia Beach
Unrated