[Teach Youself SQL in 10 Minutes] inserting data

 1. Inserting Retrieved Data

INSERT INTO Customers(cust_id,

    cust_contact,

    cust_email,

    cust_name,

    cust_address,

    cust_city,

    cust_state,

    cust_zip,

    cust_country)

SELECT cust_id,

    cust_contact,

    cust_email,

    cust_name,

    cust_address,

    cust_city,

    cust_state,

    cust_zip,

    cust_country

FROM CustNew;

 

The SELECT statement used in an INSERT SELECT can include a WHERE clause to filter the data to be inserted.

 

Column Names in INSERT SELECT This example uses the same column names in both the INSERT and SELECT statements for simplicity's sake. But there is no requirement that the column names match. In fact, the DBMS does not even pay attention to the column names returned by the SELECT. Rather, the column position is used, so the first column in the SELECT (regardless of its name) will be used to populate the first specified table column, and so on.

 

2. Copying from One Table to Another

SELECT *

INTO CustCopy

FROM Customers;

 

Not Supported by DB2

 

你可能感兴趣的:(db2)