Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. MSSQL 2000 trigger on update [modified]

MSSQL 2000 trigger on update [modified]

Scheduled Pinned Locked Moved Database
helpquestiondatabasesql-serverannouncement
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ronni Marker
    wrote on last edited by
    #1

    Hi Guys, Havent been working much on triggers and well have to get one to work now, so need some help to get the holy grail. I have a table called username and when ever a record have been changed I need to update the last update time in column lastvisittime. The problem is that with this trigger below it updates every record in the table and not just the single one that is being updated. CREATE TRIGGER [TimeUpdate] ON [dbo].[username] FOR UPDATE AS UPDATE username set lastvisittime = dbo.TINT(getdate()) Generally I need to know how do I find out what row was currently supposed to be updated? Isteadof updating the whole table as it does now. Have been trying good old uncle google but didnt find any clue to it, so hope the experts here can help :) N.b. dbo.TINT(getdate()) is just a function that changes the datetime to an int value. Cheers, Ronni

    modified on Saturday, April 5, 2008 6:57 AM

    R 1 Reply Last reply
    0
    • R Ronni Marker

      Hi Guys, Havent been working much on triggers and well have to get one to work now, so need some help to get the holy grail. I have a table called username and when ever a record have been changed I need to update the last update time in column lastvisittime. The problem is that with this trigger below it updates every record in the table and not just the single one that is being updated. CREATE TRIGGER [TimeUpdate] ON [dbo].[username] FOR UPDATE AS UPDATE username set lastvisittime = dbo.TINT(getdate()) Generally I need to know how do I find out what row was currently supposed to be updated? Isteadof updating the whole table as it does now. Have been trying good old uncle google but didnt find any clue to it, so hope the experts here can help :) N.b. dbo.TINT(getdate()) is just a function that changes the datetime to an int value. Cheers, Ronni

      modified on Saturday, April 5, 2008 6:57 AM

      R Offline
      R Offline
      Ronni Marker
      wrote on last edited by
      #2

      Okay found out myself. CREATE TRIGGER [TimeUpdate] ON [dbo].[username] FOR UPDATE AS DECLARE @ID int Select @ID = id from inserted UPDATE username set lastvisittime = dbo.TINT(getdate()) where id = @ID

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups