---
title: "How to Insert record of a table in History table by stored procedure before update that record"  
description: "How to Insert record of a table in History table by stored procedure before update that record"  
author: "Ravi Vishwakarma"  
published: 2021-10-13  
updated: 2021-10-14  
canonical: https://www.mindstick.com/forum/156782/how-to-insert-record-of-a-table-in-history-table-by-stored-procedure-before-update-that-record  
category: "mssql server"  
tags: ["sql server"]  
reading_time: 2 minutes  

---

# How to Insert record of a table in History table by stored procedure before update that record

[Insert](https://www.mindstick.com/blog/173/executing-insert-delete-or-update-query-in-sqlserver-using-ado-dot-net) a record of UserDetails [table](https://www.mindstick.com/articles/43918/how-to-design-table-using-bootstrap) in its UserHistory table by using [store procedure](https://www.mindstick.com/forum/193/auto-increment-by-store-procedure) before the [update](https://www.mindstick.com/forum/156353/what-is-hummingbird-update) that record in UserDetails in [SQL server](https://www.mindstick.com/articles/12999/what-is-table-valued-function-in-sql-server).

## Replies

### Reply by Ashutosh Kumar Verma

**Stored [Procedure](https://www.mindstick.com/forum/32/stored-procedure-return-datatype) for Insert Record in TableHistory Table before update that Record in TableDetails table in [SQL](https://www.mindstick.com/articles/13115/types-of-keys-in-sql-or-oracle-database) 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](https://www.mindstick.com/mindstickforums/cd72dd09-8185-4e24-a1c5-ff3cb6c3c524/images/d9c42369-fb34-4f35-971f-3432177361c1.png)

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](https://www.mindstick.com/mindstickforums/cd72dd09-8185-4e24-a1c5-ff3cb6c3c524/images/85f2875e-a6b6-4c19-b549-a845c5413eb9.png)

![How to Insert record of a table in History table by stored procedure before update that record](https://www.mindstick.com/mindstickforums/cd72dd09-8185-4e24-a1c5-ff3cb6c3c524/images/b5faf7ef-f5eb-4911-8aef-127f1610166f.png)\

Here I have create UserHistory table,

![How to Insert record of a table in History table by stored procedure before update that record](https://www.mindstick.com/mindstickforums/cd72dd09-8185-4e24-a1c5-ff3cb6c3c524/images/4c482c56-13ca-4b2a-969d-95782c46f7ad.png)

![How to Insert record of a table in History table by stored procedure before update that record](https://www.mindstick.com/mindstickforums/cd72dd09-8185-4e24-a1c5-ff3cb6c3c524/images/0e8bb6c9-9ccc-4869-9dd4-5c611ca9e5f6.png)\

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](https://www.mindstick.com/mindstickforums/cd72dd09-8185-4e24-a1c5-ff3cb6c3c524/images/cf2fced2-e6c6-480d-a73d-43bb3147ba43.png)\

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](https://www.mindstick.com/mindstickforums/cd72dd09-8185-4e24-a1c5-ff3cb6c3c524/images/711fe926-4e5b-4b40-a706-153c16d5e42b.png)

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](https://www.mindstick.com/mindstickforums/cd72dd09-8185-4e24-a1c5-ff3cb6c3c524/images/82db07e2-aebb-47f7-9f31-4e80e0e32498.png)\

And check the Userhistory table also

![How to Insert record of a table in History table by stored procedure before update that record](https://www.mindstick.com/mindstickforums/cd72dd09-8185-4e24-a1c5-ff3cb6c3c524/images/7c82f211-bae3-4175-9942-791206427a3d.png)\

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

\


---

Original Source: https://www.mindstick.com/forum/156782/how-to-insert-record-of-a-table-in-history-table-by-stored-procedure-before-update-that-record

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
