I have 3 tables that I have to delete data, but I have a problem.
I have this query made
DELETE FROM dbo.SalidaVTP
WHERE SalidaVTP.id IN
(SELECT Solicitud.id FROM dbo.Solicitud WHERE Solicitud.FechaCreacion > @DATE);
How can I save the data that I have deleted? In other words, from the table SalidaVTP
there are two data that I am interested in ID
deleting and ReabastecidaId
they are two data that are included in salidaVTP
, but I am interested in knowing what I am deleting. Not the ones left.
How can I get this data?
You can use the clause
OUTPUT
next toDELETE
to save the data you are interested in:There are different options, the first one would be to create a
TRIGGER
deletion. In any case you need a table to store the deleted data.When data is deleted in the table, it
SalidaVTP
will save the deleted elements in the tableBorrados
automatically.Another option is to do it manually, before deleting