Solved

db2 sql: Is it possible to create table from an existing view, copying data too?

Posted on 2011-03-07
5
801 Views
Last Modified: 2012-05-11
db2 sql: Is it possible to create a table from an existing view, copying both data and structure fields?
0
Comment
Question by:bobdylan75
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 18

Accepted Solution

by:
Dave Ford earned 400 total points
ID: 35058400

Simple enough ...
create table MyNewTable as (
  select whatever
    from MyView
)
with data

Open in new window

0
 
LVL 45

Assisted Solution

by:Kent Olsen
Kent Olsen earned 100 total points
ID: 35058402
Hi Bob,

DB2 generally requires that you create the table and populate it in separate steps.  That's a pretty small limitation though.


  CREATE TABLE mytable AS (SELECT * FROM myview) DEFINITION ONLY;

  INSERT INTO mytable SELECT * FROM myview;

You'll have to modify that slightly if the table has an IDENTITY column, and you'll have to reapply any foreign keys, triggers, or constraints that you need.


Good Luck,
Kent
0
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 35058410
Hi Dave.

'with data'.  When did that come into existence?


(pretty cool)

Kent
0
 
LVL 18

Expert Comment

by:Dave Ford
ID: 35058589
Hi Kent,

I’m currently using 6.1 (a.k.a. V6R1) on System i (a.k.a. AS/400). From the SQL Reference manuals, I can see that the "WITH DATA" functionality existed in 5.4 (in 2006) and 5.3 (in 2005), but I don’t see that functionality listed in the 5.1 manual (from 2001).

I no longer have the 5.2 manual, so I can't check that one.

I don't know how that translates to DB2 on other platforms, though.

HTH,
DaveSlash
0
 

Author Closing Comment

by:bobdylan75
ID: 35059128
thanks
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question