Jacob Alley Jacob Alley - 3 months ago 13
SQL Question

"Deletes are not allowed as it will invalidate the Meta Vaut AuditLog" SQL Server

use DatabaseExample
go

DELETE FROM schema1.table1;
DELETE FROM schema2.table2;
DELETE FROM schema3.table3;

EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"


I have changed the names of the tables/databases as I do not want to risk sharing sensitive information. However Whenever I attempt to delete a table from SCHEMA2, it gives me the following message :


Msg 50000, Level 16, State 1, Procedure tdel_Batches, Line 21

Deletes are not allowed as it will invalidate the Meta Vault AuditLog. You can disable the trigger at your own risk.

Msg 3609, Level 16, State 1, Line 11

The transaction ended in the trigger. The batch has been aborted.


I tried disabling the triggers for the entire server but that had no affect. Like i said it is only tables in a specific schema, the others are fine. The two stored procedures are to disable any key constraints and then re enable them after I am done.

Answer

The error seems to be in the triggers, so you should try disabling them in the tables that you want to delete data from:

sp_msforeachtable 'ALTER TABLE ? DISABLE TRIGGER all';

If you want to enable them again afterwards, then you can do;

sp_msforeachtable 'ALTER TABLE ? ENABLE TRIGGER all';