Home > Ask the AS/400 Experts > DB2/400 and DB2 UDB Questions & Answers > Creating SQL views
Ask The iSeries 400 Expert: Questions & Answers
EMAIL THIS

Creating SQL views

Kent Milligan EXPERT RESPONSE FROM: Kent Milligan

Pose a Question
Other iSeries 400 Categories
Meet all iSeries 400 Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 20 May 2005
Is there a way to create a SQL view where fields are dynamically obtained each time the View is used. I am trying to do an analogy with the Logical Files ability to handle not mapped fields, and each time the Physical File is modified, the Logical one reflects the change without any DDS change for their structure.

For example:

Step 1 -- I created a table (testtable) with four fields (i.e. field1, field2, field3, field4)

Step 2 --I created two SQL views, using the following SQL statements:

CREATE VIEW library/testview1 AS SELECT field1,field2,field3,field4 FROM library/testtable;

CREATE VIEW library/testview2 AS SELECT * FROM library/testtable

Step 3 -- I added a field (i.e. field5) to the

Step 4 -- I ran a query SELECT from both views, and both of them gave me the same result, in this case only the four fields. When I ran the query for the testview2, I wanted to see the field5 in the given result, however, it appears the structure's view is taken solving the SELECT * statement and remains static forever.

As you can see, a SQL view doesn't have the same behavior as a native OS/400 Logical File, due to the LF offer the ability to reference fields in a static or dynamic way.


>
I assume that you are using ALTER TABLE to dynamically add a new column to the table. Once the view has been created (even if it has been created as you described), it cannot dynamically add new columns as new columns are added to the FROM table. This behavior follows ANS and ISO SQL standards. The standard dictates that adding a new column does not affect any of the views.

For the view to be redefined to pull in the new columns you would have to delete and recreate the view as follows:

DROP VIEW library/testview1;
CREATE VIEW library/testview2 AS SELECT * FROM library/testtable

However, you would not have to recompile any programs that use this view.

==================================
MORE INFORMATION ON THIS TOPIC
==================================

Visit the ITKnowledge Exchange and get answers to your DB2 questions fast.

Check out this Search400.com Featured Topic: Expert advice on DB2

Search400.com's targeted search engine: Get relevant information on DB2/400.


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
DB2/400 and DB2 UDB
When is the YES option for 'reuse deleted files' function the best choice?
Monitoring members 'stuck' within a physical file on an EDI system
Developing tables in a parent-child relationship in DB2
SQL server error message -321
Creating a host variable of the 'where in' statement in SQL
Choose which column names are returned via ODBC when working with DB2 files
Allow access to data from a stored procedure result set using COBOL or RPG
Access path and an open data path differences
Convert a numeric physical file to a character in SQL without leading zeros
Inserting data from a CTE into a file in SQL

DB2 UDB (universal databases)
Oracle boasts 11g on SPARC is faster than IBM DB2 on Power 595
When is the YES option for 'reuse deleted files' function the best choice?
Monitoring members 'stuck' within a physical file on an EDI system
Developing tables in a parent-child relationship in DB2
SQL server error message -321
Creating a host variable of the 'where in' statement in SQL
Choose which column names are returned via ODBC when working with DB2 files
Access path and an open data path differences
Database performance comparisons on IBM i
Implement variables in SQL when creating an alias
DB2 UDB (universal databases) Research

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



iSeries Networking - Printing, Remote Access, TCP/IP
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts