How to Insert record of a table in History table by stored procedure before update that record

Insert a record of UserDetails table in its UserHistory table by using store procedure before the update that record in UserDetails in SQL server.
Last updated:10/14/2021 12:50:24 AM

1 Answers

Ashutosh Kumar Verma
Ashutosh Kumar Verma

Stored Procedure for Insert Record in TableHistory Table before update that Record in TableDetails table in SQL Server :

 Suppose I have create two tables one is ‘Users’ table and other is ‘UserHistory ‘ table. Users table stores record of all Users and UserHistory table maintain the record of Users when any User update his record. Here if a User update his record from ‘ Users’ table then before update that particular record will stored in ‘ UserHistory’ table then record is successfully updated from ‘ Users’ table.

Example:

Lets create two table in SQL server Users and UserHistory.

How to Insert record of a table in History table by stored procedure before update that record

I have insert values in above table like this-

How to Insert record of a table in History table by stored procedure before update that record

How to Insert record of a table in History table by stored procedure before update that record

Here I have create UserHistory table,

How to Insert record of a table in History table by stored procedure before update that record

How to Insert record of a table in History table by stored procedure before update that record

I have create a Stored Procedure for maintain history of Users.

How to Insert record of a table in History table by stored procedure before update that record

Here execute the above procedure for update the record from Users table.

How to Insert record of a table in History table by stored procedure before update that record

Show the Users table record is Updated where Email= ravi@gmail.com

How to Insert record of a table in History table by stored procedure before update that record

And check the Userhistory table also

How to Insert record of a table in History table by stored procedure before update that record

The above table ‘UserHistory’ contains the old record of ‘Users’ table that are Updated.


Answer