Hi @CEO ,
Please refer below example and check whether it is helpful to you.
create table testusers
(userid int,
[password] varchar(20))
insert into testusers values
(1,'password1'),
(2,'password2'),
(3,'password3')
create table pswlog
(userid int,
oldpassword varchar(20),
newpassword varchar(20),
updatetime datetime)
Create one trigger on PARTICULAR column.
CREATE TRIGGER psw_trigger
ON testusers
AFTER UPDATE
AS
IF ( UPDATE ([password]) )
BEGIN
insert into pswlog
select a.userid,c.password,a.password,getdate() from inserted a
inner join testusers b on a.userid=b.userid
inner join deleted c on a.userid=c.userid
END;
Fire this trigger.
update testusers set password='password11' where userid=1
update testusers set password='password111' where userid=1
update testusers set password='password22' where userid=2
Validate the pswlog table.
select * from pswlog
Output:
userid oldpassword newpassword updatetime
1 password1 password11 2021-09-14 10:11:41.890
1 password11 password111 2021-09-14 10:11:46.443
2 password2 password22 2021-09-14 10:11:53.387
Best regards,
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.