We have moved to www.dataGenX.net, Keep Learning with us.

Monday, December 08, 2014

Create table from another table in DB2 database


We can create a table from another table definition but without data in DB2. We need write a another sql to insert the data into newly created table.

Let's see how to do this --



Create Duplicate table with NO DATA
-----------------------------------------------------------------------------------------------------------
-- Create table from another table definistion
create table tab1 as ( select col1, col2 from table2 ) with no data ;
view raw CrtTableDB2.sql hosted with ❤ by GitHub
-----------------------------------------------------------------------------------------------------------


Insert data into duplicated table from original table
-----------------------------------------------------------------------------------------------------------
-- Insert data into duplicated table from original table
insert into tab1 select col1, col2 from table2 ;
view raw insDataDB2.sql hosted with ❤ by GitHub
-----------------------------------------------------------------------------------------------------------




Like the Facebook Page & join Group
https://www.facebook.com/DataStage4you
https://www.facebook.com/groups/DataStage4you

https://twitter.com/datastage4you
https://groups.google.com/d/forum/datastage4you
For WHATSAPP group , drop a msg to 91-88-00-906098






No comments :

Post a Comment