如何用触发器记录删除了哪些记录?并且排除掉修改的...
CREATE TRIGGER getdelinfo_8018 ON [dbo].[TB_8018]
FOR INSERT, UPDATE, DELETE
AS
INSERT INTO DELINFO(TABLENAME,TMSTAMP)
SELECT 'TB_8018',CONVERT(BIGINT,TMSTAMP)
FROM DELETED
为什么修改的记录的信息也进入delinfo表了???
------解决方案--------------------Deleted 表用于存储 DELETE 和 UPDATE 语句所影响的行的复本。在执行 DELETE 或 UPDATE 语句时,行从触发器表中删除,并传输到 deleted 表中。Deleted 表和触发器表通常没有相同的行。
当 UPDATE 时 Deleted 表记录的是更新前的数据
CREATE TRIGGER getdelinfo_8018 ON [dbo].[TB_8018]
FOR DELETE
AS
INSERT INTO DELINFO(TABLENAME,TMSTAMP)
SELECT 'TB_8018 ',CONVERT(BIGINT,TMSTAMP)
FROM DELETED
------解决方案--------------------UPDATE的原理是先DELETE 再INSERT 所以如果需要从INSERTED里面取数据的话 UPDATE是没办法排除在外的