If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Copy of a Table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-23-08, 10:42
mgupta mgupta is offline
Registered User
 
Join Date: Oct 2003
Posts: 80
Copy of a Table

I need to store the data from a view into a table.

I am using this syntax to create the table and select the data from the view.

Create table sch.t1 as (select * from sch.v1).

This works in oracle but not in DB2.

Can somebody help ?


thanks
Reply With Quote
  #2 (permalink)  
Old 04-23-08, 10:59
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
That would be a two-step process with DB2:
Code:
create table sch.t1 like sch.v1;
insert into sch.t1 select * from sch.v1;
You can find more details here:
http://publib.boulder.ibm.com/infoce...n/r0000927.htm
Reply With Quote
  #3 (permalink)  
Old 04-23-08, 11:15
mgupta mgupta is offline
Registered User
 
Join Date: Oct 2003
Posts: 80
thanks so much.
Reply With Quote
  #4 (permalink)  
Old 04-23-08, 13:03
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
You can also use the EXPORT and IMPORT commands. If you use IXF data format and use the REPLACE_CREATE option with the IMPORT, the table will be created if it does not already exist and the primary keys and indexes will be recreated the same as the source table (unlike CREATE TABLE LIKE ...). The only thing not created are the foreign keys (which is obvious since the other tables may not exist).

If you are IMPORTing a file with a lot of rows, be sure to use the COMMITCOUNT option (1000 is fine) to do intermediate commits to avoid filling up the log.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #5 (permalink)  
Old 04-24-08, 11:02
udbraja udbraja is offline
Registered User
 
Join Date: Sep 2004
Posts: 111
db2 "create table xa1 as (select * from employee) definition only in DMS_16K_TS1 partitioning key...." SO on....

This above command is more flexible to create a COPY of a table.

-Raj
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On