COPY DATA FROM ONE TABLE TO ANOTHER IN SQL SERVER 2005

CREATE TABLE EMPLOYEE
(
id INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
EMPNAME VARCHAR(100),
SALARY DECIMAL
)

INSERT INTO EMPLOYEE
SELECT ‘Pawan’ , 180000
UNION ALL
SELECT ‘Gaurav’ , 80000
UNION ALL
SELECT ‘Saurabh’ , 80000
UNION ALL
SELECT ‘Pawan’ , 830000
UNION ALL
SELECT ‘Neelam’ , 80000

SELECT * FROM EMPLOYEE

CREATE TABLE COPYEMPLOYEE
(
id INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
EMPNAME VARCHAR(100),
SALARY DECIMAL
)

—USE the following query to copy data from table to another

INSERT INTO COPYEMPLOYEE
SELECT EMPNAME ,  SALARY FROM EMPLOYEE

–CHECK Data in the new data

SELECT * FROM COPYEMPLOYEE

Share Knowledge.We all are here to learn.

Pawan Kumar

Pawankkmr@hotmail.com

Advertisements