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

  • Negative results
    ... Andrew J. Kelly wrote: ... Sorry thanks for pointing that out Kevin. ... Andrew J. Kelly SQL MVP ... Your best option to begin with is to look at the virtual file stats to seehow ...
    (microsoft.public.sqlserver.server)
  • Re: Extremely high % Disk Time .. How is this possible??
    ... Andrew J. Kelly SQL MVP ... > Slicing them into logical drives may look better but it does not increase ... I prefer to look at disk queue ... >>> Andrew J. Kelly SQL MVP ...
    (microsoft.public.sqlserver.clustering)
  • Re: disk I/O tool
    ... Andrew J. Kelly SQL MVP ... "Jay" wrote in message ... I guess he really doesn't understand SAN's very well either because SAN's are notoriously slow for writing small but frequent I/O's and direct attached drives will often outperform them hands down. ...
    (microsoft.public.sqlserver.server)
  • Re: Procedure execution problem - Clients performances
    ... Again check the parameters and plan with a trace. ... Andrew J. Kelly SQL MVP ... Dim conn As New SqlConnection ...
    (microsoft.public.sqlserver.clients)
  • Re: Performance really poor if calling data from sql clients
    ... Andrew J. Kelly SQL MVP ... The TCP connection is running from the client ... On a computer running the test which is not the database hosting ...
    (microsoft.public.sqlserver.clients)