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 > table as select..

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-02-03, 08:23
downtown downtown is offline
Registered User
 
Join Date: Dec 2003
Location: Italy
Posts: 11
Unhappy table as select..

Hi all,
I'm a newby db2 dba, but a little expert from oracle..
I'm simply tring to create a new table from another pre-existing one using a statement like this:

create table tab_name
as select * from other_table

But db2 give me the classic syntax error sql0104n..

The questions are:

Can I create a table from an existing one with same structure and data like in oracle?

If so, what is the right syntax?

Thanks in advance
downtown
Reply With Quote
  #2 (permalink)  
Old 12-02-03, 08:39
downtown downtown is offline
Registered User
 
Join Date: Dec 2003
Location: Italy
Posts: 11
Re: table as select..

Please anybody can help me?

Quote:
Originally posted by downtown
Hi all,
I'm a newby db2 dba, but a little expert from oracle..
I'm simply tring to create a new table from another pre-existing one using a statement like this:

create table tab_name
as select * from other_table

But db2 give me the classic syntax error sql0104n..

The questions are:

Can I create a table from an existing one with same structure and data like in oracle?

If so, what is the right syntax?

Thanks in advance
downtown
Reply With Quote
  #3 (permalink)  
Old 12-02-03, 09:08
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
In DB2 you need to do it as a two step process. First create the table, then insert the data.

CREATE TABLE MyTable2 like MyTable1
INSERT INTO MyTable2 select * from MyTable1;

HTH

Andy
Reply With Quote
  #4 (permalink)  
Old 12-02-03, 09:13
downtown downtown is offline
Registered User
 
Join Date: Dec 2003
Location: Italy
Posts: 11
Thank you so much Andy

Quote:
Originally posted by ARWinner
In DB2 you need to do it as a two step process. First create the table, then insert the data.

CREATE TABLE MyTable2 like MyTable1
INSERT INTO MyTable2 select * from MyTable1;

HTH

Andy
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