0

I want to create a duplicate table in dashDB (with or without the original data, it does not really matter, the table structure is what is important).

I tried:

SELECT * INTO new_table 
FROM old_table;

but I get this error:

"new_table" is not valid in the context where it is used.. SQLCODE=-206, SQLSTATE=42703, DRIVER=3.69.56

I also tried:

CREATE TABLE new_table AS 
(SELECT * FROM old_table); 

but I get this error:

An unexpected token "END-OF-STATEMENT" was found following "AS (SELECT * FROM old_table". Expected tokens may include: "WITH DATA, WITH NO DATA".. SQLCODE=-104, SQLSTATE=42601, DRIVER=3.69.56

Mike Pala
  • 766
  • 1
  • 11
  • 39

2 Answers2

0

I found an answer here:
Create table (structure) from existing table

seems this did the trick

CREATE TABLE new_table LIKE old_table;

Community
  • 1
  • 1
Mike Pala
  • 766
  • 1
  • 11
  • 39
0

Just do this. This will work and create an exact copy of the table including data:

CREATE TABLE NEW_TAB AS (SELECT * FROM EXISTING_TAB) WITH DATA;