Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want do something before or instead of update , i create this trigger ,

SQL
create trigger CarTriggerBeforeUpdate
on dbo.Cars
INSTEAD OF UPDATE
AS
BEGIN
   insert into CarTriggerUpdateDelete(Car_id, Car_No, Car_No_2)
   select Car_id, Car_No, Car_No_2 from Cars
   where Car_id = @Value //i want pass value here 
END


What I have tried:

how i do that i want insert row from table to another table before update it
Posted
Updated 10-Aug-16 21:49pm

1 solution

C#
Triggers cannot pass parameters - you have to operate within the database operation. Therefore, unless the Cars table has a CreateBy or LastUpdateBy referencing the id of the user making the change, you would need to wrap the INSERT into a stored procedure that would perform that check before performing the INSERT.

If by chance your Cars table has a CreateBy that contains the id of the user performing the change, then a trigger such as this below should work:


SQL
CREATE TRIGGER tg_Cars_Register ON dbo.Cars
AFTER INSERT AS
BEGIN
    IF EXISTS (SELECT * FROM INSERTED WHERE CreateBy <> 1110) BEGIN
        RAISERROR('Unauthorized parking', 16, 1)
        ROLLBACK
        RETURN
    END
END
GO
 
Share this answer
 
Comments
MahmoudOmar 11-Aug-16 5:31am    
i want instead of update the row from c# application the date insert into table that i created that is i want

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900