Sample Header Ad - 728x90

Its possible create a trigger after every transact in all DB? (SQL SERVER)

0 votes
1 answer
60 views
I have 100+ databases in my instace of SQL SERVER and mostly is a legacy DB but i dont have a control of what is new and what is old. My idea is create a Trigger in all server for every transact and INSERT in table for audit. I create this table on master: CREATE TABLE Audit_Logins (Login_Name NVARCHAR(256), Login_Time DATETIME, Db_name NVARCHAR(100), Host_Name NVARCHAR(200) ); And try create a trigger on LOGON for store this information CREATE TRIGGER insert_log_on_logon ON ALL SERVER FOR LOGON AS DECLARE @login NVARCHAR(200); DECLARE @db NVARCHAR(100); SET @login = ORIGINAL_LOGIN(); SET @db = DB_NAME(); IF(@login LIKE '%domain%' AND @db NULL) BEGIN INSERT INTO Audit_Logins SELECT ORIGINAL_LOGIN(), GETDATE(), DB_NAME(), EVENTDATA().value('(/EVENT_INSTANCE/ClientHost)', 'NVARCHAR(128)'); END But this doesnt work, if i run a select or any other command not fire the trigger.
Asked by Gabriel de Almeida Alves Pinto (11 rep)
Nov 18, 2021, 02:12 PM
Last activity: Nov 18, 2021, 02:44 PM