`

[Teach Youself SQL in 10 Minutes] inserting data

    博客分类:
  • db
DB2 
阅读更多

 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

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics