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.
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.
I have insert values in above table like this-
Here I have create UserHistory table,
I have create a Stored Procedure for maintain history of Users.
Here execute the above procedure for update the record from Users table.
Show the Users table record is Updated where Email= ravi@gmail.com
And check the Userhistory table also
The above table ‘UserHistory’ contains the old record of ‘Users’ table that are Updated.