Is there an easy way to copy a table to the same database of course with different name. I tried some of these listed below,
db2 "CREATE TABLE SCHEMA.NEW_TB COPY AS SELECT * FROM SCHEMA.OLD_TB WHERE 1 = 2"
db2 "SELECT INTO SCHEMA.NEW_TB FROM SCHEMA.OLD_TB"
db2 "SELECT * FROM SCHEMA.OLD_TB INSERT INTO SCHEMA.NEW_TB"
None of these worked I am using db2 v9.5
In Object Explorer, right-click Tables and select New Table. In Object Explorer right-click the table you want to copy and select Design. Select the columns in the existing table and, from the Edit menu, select Copy. Switch back to the new table and select the first row.
The clone table will be structurally identical to the base table in every way: same number of columns, column names, data types, as well as have the same indexes, before triggers, LOB objects and so on. All of this is done auto-magically by DB2 when it the clone table is created.
To copy the table, press CTRL+C.
You have to surround the select part with parenthesis.
CREATE TABLE SCHEMA.NEW_TB AS ( SELECT * FROM SCHEMA.OLD_TB ) WITH NO DATA
Should work. Pay attention to all the things @Gilbert said would not be copied.
I'm assuming DB2 on Linux/Unix/Windows here, since you say DB2 v9.5.
Try this:
CREATE TABLE SCHEMA.NEW_TB LIKE SCHEMA.OLD_TB; INSERT INTO SCHEMA.NEW_TB (SELECT * FROM SCHEMA.OLD_TB);
Options that are not copied include:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With