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 > Copying data from one table to another table dynamically

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-20-10, 10:14
smartcooldevil smartcooldevil is offline
Registered User
 
Join Date: Jun 2010
Posts: 17
Copying data from one table to another table dynamically

Hi,
I am new to IBM DB2, I was using Sybase T-SQL.
In sybase we can copy data from one table to another table by doing "Select * into"
e.g.
SELECT emp_no, dept_no, sal
INTO sample_table
FROM emp
WHERE ......

Here "sample_table" is dynamically created, no need to explicitely create it.

Can you please explain how can I do this in DB2?


Also In sybase, we can also create session specific dynamic table
e.g.
SELECT emp_no, dept_no, sal
INTO #tempo_table
FROM emp
WHERE .....

Here #tempo_table is session specific dyna,ic table.
Is it possible in DB2?
Reply With Quote
  #2 (permalink)  
Old 07-20-10, 11:10
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by smartcooldevil View Post
In sybase we can copy data from one table to another table by doing "Select * into"
e.g.
SELECT emp_no, dept_no, sal
INTO sample_table
FROM emp
WHERE ......

Here "sample_table" is dynamically created, no need to explicitely create it.

Can you please explain how can I do this in DB2?
You could do that with a CREATE TABLE statement:

CREATE TABLE ... AS SELECT ...

This creates a materialized query table; check the manual for available options.




Quote:
Originally Posted by smartcooldevil View Post
Also In sybase, we can also create session specific dynamic table
e.g.
SELECT emp_no, dept_no, sal
INTO #tempo_table
FROM emp
WHERE .....

Here #tempo_table is session specific dyna,ic table.
Is it possible in DB2?
Check the DECLARE GLOBAL TEMPORARY TABLE statement.
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