4.2.2 The INSERT statement

The INSERT statement

Inserts one or more tuples in a table.

General forms:

To insert a single tuple

INSERT INTO []

VALUES ;

To insert multiple tuples

INSERT INTO []

SELECT [ ALL | DISTINCT ]

FROM *

[ WHERE ];

* - list of existing tables

Sample INSERT statements from the Case Example

Query 34: Insert all values for a new row

INSERT INTO customers <-------------------

VALUES (006, 'Krishnan', 'Madras');

Inserts a single row in Customers Table. Attribute list need not be mentioned if values are given for all attributes in the tuple.

Query 35: Insert values of item# & descr columns for a new row

INSERT INTO items (item#, descr) <----------

VALUES ('HW4', '132-DMPrinter');

Attribute list mentioned since values are not given for all attributes in the tuple. Here Price column for the newly inserted tuple takes NULL value.

Query 36: Inserts a new row which includes a date field

INSERT INTO ord_aug

VALUES(106, '31-AUG-94', 005);

Query 37: Inserts a new row with the date field being specified in non DD-MON-YY format

INSERT INTO ord_aug

VALUES (106, TO_DATE('310894','DDMMYY'), 005);

Powered by Blogger.