Welcome to Sign in | Help

Re: TIMESTAMP

  •  04-09-2008, 5:47 PM

    Re: TIMESTAMP

    cretzu:
    Pai din aplicatia C# ar putea din greseala o anumita functie de SAVE sa faca un astfel de update pe toate articolele.
    Coduri din aplicatie nu pot publica pentru ca nu prea aj la ele :( ma ocup de SQL si cam atat.

    Eu zic ca este un scenariu curent.
    Cat desptre codul de SQL ... acesta este urmatorul.

    ALTER TABLE Participant ADD UltimaModificare DATETIME CONSTRAINT  Ultima_Default DEFAULT getdate()

    IF EXISTS (SELECT * FROM sysobjects
                WHERE id = OBJECT_ID(N'[dbo].[Participant_TRTimeStamp]')
                        AND type in (N'TR')
                )
        DROP TRIGGER [dbo].[Participant_TRTimeStamp]
    GO

    CREATE TRIGGER [dbo].[Participant_TRTimeStamp]
    ON [dbo].[Participant]
    AFTER UPDATE
    AS
    BEGIN
        UPDATE Participant SET UltimaModifcare = getdate()
        WHERE ID_Participant =
            (
                SELECT ID FROM INSERTED
            )
    END
    GO

    iar apoi am incercat cu UPDATE PArticipant SET Nume = 'x'
    Nu am index pe campul Nume pentru ca asta ar incetini si m mult



    CREATE TABLE Produs
    (
      ID INT IDENTITY(1,1) PRIMARY KEY,
      Denumire VARCHAR(50) NOT NULL,
      UltimaModificare DATETIME DEFAULT GETDATE() NOT NULL
    )
    GO

    /*
    WHILE 1 = 1
      INSERT INTO Produs (Denumire) VALUES ('A')
    GO
    */

    CREATE TRIGGER trgProdusUpdate
    ON Produs
    AFTER UPDATE
    AS
    IF NOT UPDATE(UltimaModificare)
      UPDATE Produs
      SET UltimaModificare = GETDATE()
      FROM Produs INNER JOIN inserted ON Produs.ID = inserted.ID
    GO

    UPDATE Produs
    SET Denumire = 'C'
    GO

    In declansator foloseste jonctiune si nu subinterogare.
View Complete Thread
Powered by Community Server (Commercial Edition), by Telligent Systems