db2

Copy table with or without data

Introduction#

Example of how to copy existing table structure with/without data

Syntax#

  1. CREATE TABLE schemaName.table AS (SELECT columns FROM schemaName.table) WITH DATA

Copy Table With Data

CREATE TABLE myschema.tableNew AS (
    SELECT *
    FROM myschema.tableOld
) WITH  DATA

Copy Table without data

CREATE TABLE myschema.tableNew AS (
    SELECT *
    FROM myschema.tableOld
) WITHOUT  DATA

Copy Table with where clause

CREATE TABLE myschema.tableNew AS (
    SELECT *
    FROM myschema.tableOld
WHERE column1 = 'myCriteria'
) WITH  DATA

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow