开发者

Easy way on archiving record with EF

开发者 https://www.devze.com 2023-04-01 03:15 出处:网络
I want not to delete record from DB, but just copy it to archive table just to avoid accidents. What I found out is we can use custom stored procedure. But we cannot just add a delete stored procedure

I want not to delete record from DB, but just copy it to archive table just to avoid accidents. What I found out is we can use custom stored procedure. But we cannot just add a delete stored procedure, we have to add stored procedure for select and update also. Is there any built-in or easier开发者_Go百科 way on doing that? I just need to keep the deleted records, just in case..


I'd probably go with a separate archive table, and a trigger on deletion from the regular table, something like:

CREATE TRIGGER Foo_AD
ON  dbo.Foo
AFTER DELETE
AS 
BEGIN
    SET NOCOUNT ON;
    insert Archive_Foo (a, b)
        select a, b from deleted
END
GO
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号