Inserting using existing row data

From: Paul Krikorian <paulk_at_spock.dis.cccd.edu>
Date: 15 Jul 1993 06:57:43 -0700
Message-ID: <223non$b9c_at_spock.dis.cccd.edu>


Hi, another SQL question that I hope is not an FAQ.

My question deals with inserting a row into a table using values from an existing row within the same table. I know I can use the SELECT statement to grab values from another row within the INSERT statement itself. What I'd like is to be able to select all columns from an existing row except the key column and insert their values along with a new key value into a new row. However, to keep my application from having to know about the structure of the table (except the key column name), is there a way I can code the INSERT/SELECT statement combination without having to use any column names (maybe just the "*") other than the key column name?

Example:

    table_a


    key_col
    col_1
    col_2

    ...
    col_n

Normally, to insert a new row (with say key_col = 2) using all the columns from another row (with say key_col = 1), I could perform the following:

INSERT INTO table_a
SELECT 2,col_1,col_2,...,col_n FROM table_a WHERE key_col = 1

Is it possible to perform this type of statement without having to specify 'col_1,col_2,...,col_n', but using something generic to represent them?

I am writing a PRO*COBOL application and will have to perform this type of function on about 30 tables and I would really like not to have to maintain all those column names (or even type them out in the first place!).

Any suggestions or am I just dreaming?

Thank you in advance for any help.

-- 
Paul Krikorian                   | Internet: paulk_at_spock.dis.cccd.edu
Coast Community College District | Voice:    (714) 432-5150
1370 Adams Ave.                  | Fax:      (714) 432-5062
Costa Mesa, CA 92626, USA        |
Received on Thu Jul 15 1993 - 15:57:43 CEST

Original text of this message