---
title: "SQL: Insert new records from 1 table to another"  
description: "SQL: Insert new records from 1 table to another"  
author: "Samuel Fernandes"  
published: 2013-05-09  
updated: 2013-05-09  
canonical: https://www.mindstick.com/forum/842/sql-insert-new-records-from-1-table-to-another  
category: "mssql server"  
tags: ["mssql server"]  
reading_time: 1 minute  

---

# SQL: Insert new records from 1 table to another

Hi Everyone!\
I want to update [table from another table](https://www.mindstick.com/forum/190/create-a-new-table-from-another-table) data using stored [procedure in SQL](https://www.mindstick.com/forum/158350/what-is-a-stored-procedure-in-sql-server-and-how-to-create-one) server. For example I have two table tbl_1 and tbl_2. I want to copy new [insert data](https://www.mindstick.com/forum/33964/insert-data-in-datagridview-from-text-box-c-sharp) of tbl_1 to tbl_2.\
my [stored procedure](https://www.mindstick.com/articles/803/using-stored-procedure-in-asp-dot-net) as following\
CREATE PROCEDURE [dbo].[CHECK_NEW]\
ASbegin [transaction](https://www.mindstick.com/blog/175/transactions-in-database)\
declare @tempId intdeclare @tempName [varchar](https://www.mindstick.com/forum/161878/what-is-the-difference-between-nvarchar-and-varchar)\
DECLARE c1 CURSOR FOR SELECT kId, kNameFROM table1\
OPEN c1\
FETCH NEXT FROM c1 INTO @tempId, @tempName\
WHILE @@FETCH_STATUS = 0 BEGIN\
if (SELECT sId FROM table2) NOT IN(@tempId)insert into table(sId, name) values(@tempId, @tempName)END\
please help me!\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)

## Replies

### Reply by AVADHESH PATEL

Hi Samuel!\
You can try as following \
CREATE [PROCEDURE](https://www.mindstick.com/forum/32/stored-procedure-return-datatype) [dbo].[CHECK_NEW]ASBegin Trybegin transaction Insert into Table2(ulid,Id,Name) Select newid() as ulid, Id,name from Table1 a inner join Table2 b on a.id!=b.idCommitEnd TryBegin CatchRollBackEnd Catch\
I hope it resolve your problem


---

Original Source: https://www.mindstick.com/forum/842/sql-insert-new-records-from-1-table-to-another

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
