The table user1 contains the field ID, username, email, and address.
The delta2_user1 table contains the field ID, username, email, address, and status.
When table user1 inserts a record, a record is also inserted in delta2_user1, and 'insert' is written in the field status'
When user1 updates a record, delete the original record in delta2_user1, insert a new record, and write 'modify' in the field status'
When a record is deleted from table user1, the status value of the corresponding field is updated to 'delete' in delta2_user1'
Set ansi_nulls on <br/> set quoted_identifier on <br/> go <br/> alter trigger [DBO]. [delta_user2_user1] <br/> on [DBO]. [user1] <br/> for insert, update, delete <br/> as <br/> If exists (select. username from inserted a, deleted B where. username = B. username) <br/> begin <br/> If exists (select delta2_user1.username from delta2_user1, inserted where delta2_user1.username = inserted. username) <br/> Delete delta2_user1 from delta2_user1, inserted where delta2_user1.username = inserted. username; <br/> insert into delta2_user1 select ID, username, email, address, 'modify' from inserted; <br/> end </P> <p> else <br/> begin <br/> If exists (select username from inserted) <br/> begin <br/> insert into delta2_user1 select ID, username, email, address, 'insert' from inserted; <br/> end <br/> else <br/> begin <br/> Update delta2_user1 set status = 'delete' from delta2_user1, deleted where delta2_user1.username = deleted. username; <br/> end