Re: Change date with trigger

From: treemusic (treemusic.1balo4_at_mail.mcse.ms)
Date: 08/20/04


Date: Fri, 20 Aug 2004 11:45:38 -0500


strellita wrote:
> *I create this trigger, but it change all rows. I change only the
> rows that I insert or update. How can I this?
>
> CREATE TRIGGER [datep] ON [prueba]
> FOR INSERT, UPDATE
> AS
> BEGIN
> UPDATE prueba SET datepm = getdate()
> FROM inserted i
> END *

Needs:

INNER JOIN i.[id column] = preuba.[id column]

after your FROM statement
then it will work correctly.

Full example:
CREATE TRIGGER [datep] ON [prueba]
FOR INSERT, UPDATE
AS
BEGIN
        UPDATE p SET datepm = getdate()
        FROM inserted i
        INNER JOIN preueba p ON i.[ID] = p.[ID]

END
GO

Peace,
tree

--
treemusic
------------------------------------------------------------------------
Posted via http://www.mcse.ms
------------------------------------------------------------------------
View this thread: http://www.mcse.ms/message899238.html
 


Relevant Pages

  • Re: 1352 NUL bytes at the end of a page? (was Re: Assertion `s && s->tree failed: The sag
    ... Th ecurrent BK tree contains much of the anonvma stuff, ... need threads to trigger it and I've never seen threaded version control ... minor merging error), that's a black and white thing, it doesn't touch ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: So, how about that old "Eagle Eyes" Cheney?
    ... pulling the trigger, then dragging the body halfway up a tree to feed ...
    (rec.motorcycles)
  • RE: Cascade Delete within Self Referencing Table
    ... implement (category tree), there are beter ways of doing it than the dreaded ... > referential integrity. ... > DELETE statement conflicted with COLUMN SAME TABLE REFERENCE contraint ... > 2) Create a trigger that will delete child records from the parent table. ...
    (microsoft.public.sqlserver.programming)
  • Re: 2.6.0: Badness in pci_find_subsys!!
    ... > the interrupt side while something else is hotplugging a new device into ... I try to stick w/ Linus' tree, but I'll attempt to decipher the changelogs on ... It takes 47 muscles to frown, but only 4 to pull the trigger of a finely tuned ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: [RFC] ELF Relocatable x86 and x86_64 bzImages
    ... Currently there are 33 patches in my tree to do this. ... The weirdest symptom I have had so far is that page faults did not ... trigger the early exception handler on x86_64. ...
    (Linux-Kernel)