Results 1 to 3 of 3

Thread: Delete trigger.

  1. #1
    Join Date
    Sep 2010
    Posts
    153

    Smile Unanswered: Delete trigger.

    Hi guys,
    I have a doubt. I want to write on delete trigger and as i am new to database i am having some difficulty in writing it.

    I have two tables. employee_details and look_up_employee. i have data in employee_details and look_up_employee contains same structure and same data as there are in employee_details.

    If i remove any data from employee_details, then data from look_up_employee should also get deleted. I want ti write trigger for it. Can anyone write trigger for me []

    employee_details:-

    employee_name employee_dept employee_id(p.k)
    ---------------- ----------------- --------------------

    ramesh java abc-001
    rajesh testing egf-002
    hari database xyz-003
    ravi marketing uvw-004


    example- if i delete ravi's details from employee_details then same details which are in look_up_employee table, should also get deleted.

    thanks

  2. #2
    Join Date
    Sep 2010
    Posts
    153

    Smile thanks guys for viewing , its working nw :)

    Finally its working. lol, it's simple and i took couple of days for it. Here is the trigger:-



    create TRIGGER trgAfterDelete ON migration
    AFTER DELETE
    AS
    declare @id nvarchar(50);
    declare @name nvarchar(100);
    declare @dept nvarchar(50);


    select @id=d.ID ,@name=d.[name], @dept=d.dept from deleted d;

  3. #3
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Do not write your trigger this way. It will not support multi-record transactions, and you could end up corrupting your data.

    delete from look_up_employee
    inner join deleted on look_up_employee.id = employee_details.id
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •