Results 1 to 5 of 5

Thread: Simple trigger

  1. #1
    Join Date
    Oct 2003
    Location
    Netherlands
    Posts
    98

    Unanswered: Simple trigger

    HI all,

    i have a table wich contains a datetime field lastedit
    i need a trigger that updates that field with the getdate() on the record that a user updated

    Thanx
    Cheerz Wimmo

  2. #2
    Join Date
    Oct 2001
    Location
    Naples, FL
    Posts
    273
    Create trigger foo on table
    for update
    as
    update table set a.update_date = getdate()
    from table a join inserted b
    on a.prikey = b.prikey

    If this isn't clear, post your table DDL

    HTH
    ---------------
    Ray Higdon MCSE, MCDBA, CCNA

  3. #3
    Join Date
    Oct 2003
    Location
    Netherlands
    Posts
    98
    Originally posted by rhigdon
    Create trigger foo on table
    for update
    as
    update table set a.update_date = getdate()
    from table a join inserted b
    on a.prikey = b.prikey

    If this isn't clear, post your table DDL

    HTH
    Here is the table, last field is the field that should be updated!


    Code:
    CREATE TABLE [dbo].[EB_Eprom] (
    	[EpromID] [int] IDENTITY (1, 1) NOT NULL ,
    	[Naam_Spel] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    	[Versie] [nvarchar] (5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    	[Checksum1] [nvarchar] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    	[Checksum2] [nvarchar] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    	[Omschrijving] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    	[Datum_vrijgave] [smalldatetime] NULL ,
    	[Kabinet] [int] NULL ,
    	[Merk] [int] NULL ,
    	[Wet] [int] NULL ,
    	[Bestand_1] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    	[Bestand_2] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    	[Lastedit] [datetime] NULL

  4. #4
    Join Date
    Oct 2001
    Location
    Naples, FL
    Posts
    273
    Create trigger foo on EB_Eprom
    for update
    as
    update EB_Eprom set a.Lastedit = getdate()
    from EB_Eprom a join inserted b
    on a.EpromID= b.EpromID

    HTH
    ---------------
    Ray Higdon MCSE, MCDBA, CCNA

  5. #5
    Join Date
    Oct 2003
    Location
    Netherlands
    Posts
    98
    Originally posted by rhigdon
    Create trigger foo on EB_Eprom
    for update
    as
    update EB_Eprom set a.Lastedit = getdate()
    from EB_Eprom a join inserted b
    on a.EpromID= b.EpromID

    HTH
    Thanx Man, this thing workes just fine. You guys did it again for me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •