Solved

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

Posted on 2011-03-07
5
758 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
  • 2
  • 2
5 Comments
 
LVL 18

Accepted Solution

by:
daveslash 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:Kdo
Kdo 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:Kdo
ID: 35058410
Hi Dave.

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


(pretty cool)

Kent
0
 
LVL 18

Expert Comment

by:daveslash
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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 (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now