OUTPUT CLASS

  • DEAR ALL;

    How can i use the Output class;

    for Instance I want to Delete that on record these record are shown in Resultgrid;

    pls help this;

    Thanks Advance ;

    A.faijurrahuman MCA

    Coimbatore

  • Hi

    Could you be more specific, please?

    Thanks

    Flo

  • Hi Friends;

    Like the table name studentmaster

    regno studname mark

    1 Foo 88

    2 faijur 75

    3 raja 78

    Whether I want to Delete the regno=2

    the deleted entry saved in another studentmasterbkup table

    How can i write the script;

    Thanks Advance;

    A.Faijurrahuman MCA

    Coimbatore

    pls help me;

  • Hi

    There are different approaches to handle this. I would suggest the OUTPUT clause on SQL Server 2005:

    DECLARE @student TABLE

    (

    Id INT NOT NULL IDENTITY(1,1)

    PRIMARY KEY CLUSTERED

    ,Name VARCHAR(100)

    );

    DECLARE @student_audit TABLE

    (

    StudentId INT NOT NULL

    ,DeleteDate DATETIME NOT NULL

    ,Name VARCHAR(100)

    PRIMARY KEY (StudentId, DeleteDate)

    );

    INSERT INTO @student

    SELECT 'foo'

    UNION ALL SELECT 'bar';

    -- delete student and move to audit-table

    DELETE FROM @student

    OUTPUT

    deleted.Id

    ,GETDATE()

    ,deleted.Name

    INTO @student_audit

    WHERE Name = 'bar';

    SELECT * FROM @student;

    SELECT * FROM @student_audit;

    Greets

    Flo

  • Thanks for your quick response

    But in case I have to solve the problem in Trigger ;

    How can i Write the script;

    Thanks &Advance;

    A.Faijurrahuman17

  • Hi

    Have a look at the CREATE TRIGGER description. You can use an "AFTER DELETE". Within this trigger you can access a virtual table called "deleted" which contains exactly all columns of your source table.

    Greets

    Flo

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply