Re: lastmodified

From: Andrew J. Kelly (sqlmvpnooospam_at_shadhawk.com)
Date: 02/23/05


Date: Wed, 23 Feb 2005 09:41:57 -0500

That only works for Inserts. He specifically asked for Updates.

-- 
Andrew J. Kelly  SQL MVP
"Uri Dimant" <urid@iscar.co.il> wrote in message 
news:uuRRBDYGFHA.2156@TK2MSFTNGP09.phx.gbl...
> In addition to Andrew's response you can use  DEFAULT constraint
>
> CREATE TABLE #Test
> (
> col DATETIME DEFAULT GETDATE()
> )
>
> INSERT INTO #Test DEFAULT VALUES
>
>
> "Andrew J. Kelly" <sqlmvpnooospam@shadhawk.com> wrote in message
> news:eV5joCSGFHA.2976@TK2MSFTNGP09.phx.gbl...
>> CREATE TRIGGER tr_YourTrigger
>> ON YourTable
>> FOR UPDATE
>>
>> AS
>>
>>
>> IF @@ROWCOUNT > 0
>>
>> UPDATE YourTable SET [LastModified] = GETDATE()
>> WHERE YourPK IN (SELECT b.PK FROM Inserted AS b)
>>
>>
>> -- 
>> Andrew J. Kelly  SQL MVP
>>
>>
>> "Jason" <jlewis@hotmail.com> wrote in message
>> news:O$XaerRGFHA.2568@TK2MSFTNGP10.phx.gbl...
>> > Hi,
>> >
>> > Can someone provide me a simple trigger where it updates a lastmodified
>> > column.
>> >
>> > It should update the column lastmodified whenever an update occurs on
> all
>> > the other columns.
>> >
>> > Thnx
>> >
>>
>>
>
> 


Relevant Pages