可以。。 create trigger tr_t on 你的表名 for update as begin declare @n int set @n=(select id from inserted ) print '你表中ID为'+rtrim(@n)+'已经修改了!!' end
可以不用触发器,用output ,联机帮助的例子USE AdventureWorks; GO DECLARE @MyTableVar table( EmpID int NOT NULL, OldVacationHours int, NewVacationHours int, ModifiedDate datetime); UPDATE TOP (10) HumanResources.Employee SET VacationHours = VacationHours * 1.25 OUTPUT INSERTED.EmployeeID, DELETED.VacationHours, INSERTED.VacationHours, INSERTED.ModifiedDate INTO @MyTableVar; --Display the result set of the table variable. SELECT EmpID, OldVacationHours, NewVacationHours, ModifiedDate FROM @MyTableVar; GO --Display the result set of the table. --Note that ModifiedDate reflects the value generated by an --AFTER UPDATE trigger. SELECT TOP (10) EmployeeID, VacationHours, ModifiedDate FROM HumanResources.Employee; GO
可以 create trigger tr_t on 你的表名 for update as begin insert yourtable select * from inserted end
建一个触发器 AFTER update
old.列名 就是修改的列
当然也可以在修改前触发
create trigger tr_t on 你的表名
for update
as
begin
declare @n int
set @n=(select id from inserted )
print '你表中ID为'+rtrim(@n)+'已经修改了!!'
end
GO
DECLARE @MyTableVar table(
EmpID int NOT NULL,
OldVacationHours int,
NewVacationHours int,
ModifiedDate datetime);
UPDATE TOP (10) HumanResources.Employee
SET VacationHours = VacationHours * 1.25
OUTPUT INSERTED.EmployeeID,
DELETED.VacationHours,
INSERTED.VacationHours,
INSERTED.ModifiedDate
INTO @MyTableVar;
--Display the result set of the table variable.
SELECT EmpID, OldVacationHours, NewVacationHours, ModifiedDate
FROM @MyTableVar;
GO
--Display the result set of the table.
--Note that ModifiedDate reflects the value generated by an
--AFTER UPDATE trigger.
SELECT TOP (10) EmployeeID, VacationHours, ModifiedDate
FROM HumanResources.Employee;
GO
create trigger tr_t on 你的表名
for update
as
begin
insert yourtable
select *
from inserted
end
create trigger tr_t on 你的表名
for update
as
begin
insert yourtable
select *
from deleted
end
修改记录时,旧的未修改的记录放于deleted表中
新的已修改的记录放于inserted表中,根据此两表与主键,可确定修改了那些记录,字段