AFTER DELETE Trigger is not inserting multiple rows [closed]

See CREATE TRIGGER.

CREATE TRIGGER TRIG_SomeTable_Delete
    ON SomeTable AFTER DELETE
    AS
        BEGIN
            INSERT INTO SomeTable(SomeColumn)
            SELECT SomeColumn FROM DELETED
        END

DELETED can contain multiple rows, so use a SELECT instead.

In your case:

ALTER TRIGGER [tgr_del_into_plan_audit]
    ON [dbo].[agent_plan_details]
    AFTER DELETE
    AS
       BEGIN
           SET NOCOUNT ON;
           INSERT INTO agent_plan_details_audit
           (
               plan_title_id,
               plan_title,
               no_of_property_listing,
               validity_of_plan,
               Each_property_listing_life,
               list_of_property_in_search_result,
               price,
               discount,
               discount_code,
               discount_percentage,
               create_date,
               action
           )
           SELECT
               plan_title_id,
               plan_title,
               no_of_property_listing,
               validity_of_plan,
               Each_property_listing_life,
               list_of_property_in_search_result,
               price,
               discount,
               discount_code,
               discount_percentage,
               GETDATE(),
               'D'
           FROM DELETED
       END

Leave a Comment