× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



FWiW: For CREATE TABLE AS using WITH DATA to SELECT data from a relational data set, an ORDER BY clause would accomplish little more than slowing the data access\copy due to either random I\O via an INDEX or a sort as the query implementation. Best to omit that clause for performance.

Also: Be aware that the CREATE TABLE AS syntax has special clauses to carry over some specific attributes [e.g. identity; see the "copy-options" of the syntax diagram] which might not otherwise exist in the new TABLE while they do\did in the old TABLE. Some other attributes must be explicitly added on the CREATE TABLE or added later by an ALTER or a CREATE statement. For example, neither constraints nor triggers will be on the new TABLE. Additionally one must consider both ownership & authority, as well as journaling, as compared to the original file. None of those should be an issue for an ALTER TABLE, but as noted, an ALTER TABLE request has no means to rearrange the columns like the CHGPF SRCFILE(named) can effect.

Note also that long column names and long file names may not be directly functional with the given CREATE TABLE AS examples. Both a long name and a system name may need to be set for a file. For any /renamed/ columns there is no FOR COLUMN clause in the SELECT giving ability to define either of the system-column-name or long column name [aka ALIAS in DDS]. A column-list for the as-result-table would best be specified with its FOR COLUMN clause; i.e. as a better rename as contrasted with using just the AS COLUMN NAME in the column\expression-list of the SELECT. In either case, the LABEL ON and COMMENT ON may be required to get the appropriate text & COLUMN headings for the columns, and text for the file.

Regards, Chuck

Mark S. Waterbury wrote:

You could do something like this:

CREATE TABLE TGTLIB/NEWTABLE2 AS
(SELECT COLUMN1, COLUMN2, COLUMN3
, COLUMN4, COLUMN5, COLUMN6
FROM TGTLIB/OLDTABLE1
ORDER BY COLUMN1, COLUMN2)
WITH DATA
;
DROP TABLE TGTLIB/OLDTABLE1
;
RENAME TABLE TGTLIB/NEWTABLE2 TO SYSTEM NAME OLDTABLE1;

If you also want to rename some (or all) of the columns,
do it like this:

CREATE TABLE TGTLIB/NEWTABLE2 AS
(SELECT
COLUMN1 AS NEWFIELD1
, COLUMN2 AS NEWFIELD2
, COLUMN3 AS NEWFIELD3
, COLUMN5 AS NEWFIELD5
, COLUMN4 AS NEWFIELD4
, COLUMN6 AS NEWFIELD6
FROM TGTLIB/OLDTABLE1
ORDER BY COLUMN1, COLUMN2)
WITH DATA
;
DROP TABLE TGTLIB/OLDTABLE1
;
RENAME TABLE TGTLIB/NEWTABLE2 TO SYSTEM NAME OLDTABLE1;


Mike Cunningham wrote:
Is there a way to move a column(field) in an sql created table(file)? In DDS I would just rearrange the fields in
the source and do a CHGPF and the fields moved. In iSeries
Navigator I can move a column around before I create the
table but once it exists it does not let me move the columns
up or down.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.