'EVENTDATA() for DML Triggers?

I am looking to create an audit table for my database in Azure SQL Database. The best method I have across so far in order to do this is to use triggers.

I have created this trigger for now,

CREATE TRIGGER [my_schema].[trg_my_table]
ON [my_schema].[my_table]
AFTER INSERT, UPDATE, DELETE
AS
INSERT INTO [my_schema].[audit_table]
VALUES
('my_table', SUSER_SNAME(), GETDATE());

I am just logging the name of the person who performs the action and the date.

However, while I was doing my research, I came across the EVENTDATA( ) function that can be used in DDL triggers. I was wondering if there is an equivalent to this for DML triggers? Or is there some other way that I can get this information for DML operations?

You can find more information on the EVENTDATA() function here,

https://docs.microsoft.com/en-us/sql/t-sql/functions/eventdata-transact-sql?view=sql-server-ver15



Solution 1:[1]

Unfortunately there is no such function (like EVENTDATA() for DDL) available for DML triggers and you can't use EVENTDATA() for DML triggers. You need to create standard ALTER, INSTEAD OF and CLR triggers for DML as you are already doing.

You can check the functionality of these triggers here.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 UtkarshPal-MT