23.10.2012 Views

Openedge Data Management: SQL Reference - Product ...

Openedge Data Management: SQL Reference - Product ...

Openedge Data Management: SQL Reference - Product ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

INSERT<br />

Syntax<br />

Related statement<br />

REVOKE<br />

INSERT<br />

Inserts new rows into the specified table or view that will contain either the explicitly specified<br />

values or the values returned by the query expression.<br />

INSERT INTO [ owner_name.]{table_name|view_name }<br />

[ ( column_name [, column_name ] , ... ) ]<br />

{ VALUES ( value [, value ] , ... ) | query_expression } ;<br />

Examples The following provides examples of the INSERT statement:<br />

INSERT INTO customer (cust_no, name, street, city, state)<br />

VALUES<br />

(1001, 'RALPH', '#10 Columbia Street', 'New York', 'NY') ;<br />

INSERT INTO neworders (order_no, product, qty)<br />

SELECT order_no, product, qty<br />

FROM orders<br />

WHERE order_date = SYSDATE ;<br />

Notes • If the optional list of column names is specified, then only the values for those columns<br />

are required. The rest of the columns of the inserted row will contain NULL values,<br />

provided that the table definition allows NULL values and there is no DEFAULT clause for the<br />

columns. If a DEFAULT clause is specified for a column and the column name is not present<br />

in the optional column list, then the column is given the default value.<br />

• If the optional list is not specified, then the column values must be either explicitly<br />

specified or returned by the query expression. The order of the values should be the same<br />

as the order in which the columns are declared in the declaration of the table or view.<br />

• The VALUES (...) form for specifying the column values inserts one row into the table.<br />

The query expression form inserts all the rows from the query results.<br />

• A SELECT statement utilizing a NOLOCK hint can be used within an INSERT statement. For<br />

example:<br />

INSERT INTO PUB.CUSTOMER<br />

SELECT * FROM PUB.ARCHIVE_CUST WHERE ... WITH (NOLOCK);<br />

For more information using the NOLOCK hint in a SELECT statement, see “SELECT” section<br />

on page 45.<br />

• can be used if If the table contains a foreign key and there is no corresponding primary key<br />

that matches the values of the foreign key in the record being inserted, then the insert<br />

operation is rejected.<br />

39

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!