Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2010
    Posts
    25

    Unanswered: 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?

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •