Wednesday 15 July 2015

Bulk insert from one table to another table in SQL

Bulk Insert
  1. we can use two types of bulk insert in MSSQL
  2. it is very useful to transfer whole data or particular data from one table to another
  3. Type 1: we need to create schema or we can use existing schema for insertion
  4. Type 2: we cannot insert data's in existing table schema.this type will copy the schema of selected table and create table in database or we can use temp table
  5. Mostly this bulk insert are used in stored procedure or user-defined functions for calculations.
Type 1:
 CREATE TABLE TABLE1( name INT,EmpSalary BIGINT)
 INSERT INTO TABLE1
 SELECT name,salary FROM TABLE2
 WHERE salary > 1000

Type 2 :
 SELECT * INTO #TEMP FROM TABLE2 //this will create temp table with selected table schema
 WHERE salary > 1000
   OR
 SELECT * INTO TABLE FROM TABLE2   // this will create real table with selected table schema in DB
 WHERE salary > 1000

No comments:

Post a Comment