Junior — Middle
Have you used triggers in your projects to automate actions in the database?
sobes.tech AI
Answer from AI
Yes, triggers in databases are often used to automate actions when data changes — for example, for logging, validation, or synchronizing related tables.
In C# projects, triggers are usually created and managed on the DBMS side (e.g., SQL Server), and C# interacts with them through ORM or direct SQL queries.
Example of using a trigger in SQL Server:
CREATE TRIGGER trg_UpdateTimestamp
ON Orders
AFTER UPDATE
AS
BEGIN
UPDATE Orders
SET LastModified = GETDATE()
FROM inserted i
WHERE Orders.OrderID = i.OrderID;
END
This trigger automatically updates the LastModified field when a record is changed. In C#, it is enough to perform regular update operations, and the trigger will handle the additional logic.