DB2 V11- Copy Data From One Table to Another

The below are the steps we need to follow. First, we need t create a new table.

CREATE TABLE DA31.TELE
(NAME2 VARCHAR(15) NOT NULL,
NAME1 VARCHAR(12) NOT NULL,
PHONE CHAR(4))

Now new Table TELE is created. I want to copy  some old data into this new table.

INSERT INTO DA31.TELE
SELECT LASTNAME, FIRSTNME, PHONENO
FROM DA31.EMP
WHERE WORKDEPT = ‘D21’;

Now Data is copied into new table.

The CREATE TABLE statement example creates a table which, at first, is empty. The table has columns for last names, first names, and phone numbers, but does not have any rows.

The INSERT statement fills the newly created table with data that is selected from the DA31.EMP table: the names and phone numbers of employees in department D21.

This way we can copy data from one table to another table. No need to use any Tool or load utility. This is simple sql query.

Advertisements

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.