Introduction to DB2 for z/OS
Previous topic | Next topic | Contents | Glossary | Contact z/OS | PDF


Insert statements

Introduction to DB2 for z/OS

You can use an INSERT statement to add new rows to a table or view.

You can use an INSERT statement to take the following actions:

  • Specify the values to insert in a single row. You can specify constants, host variables, expressions, DEFAULT, or NULL.
  • Start of changeUse host variable arrays in the VALUES clause of the INSERT FOR n ROWS statement to insert multiple rows into a table.End of change
  • Include a SELECT statement in the INSERT statement to tell DB2® that another table or view contains the data for the new row or rows.

You can add new data to an existing table in other ways, too. You might need to add large amounts of data to an existing table. Some efficient options include copying a table into another table, writing an application program that enters data into a table, and using the DB2 LOAD utility to enter data.

Suppose that you want to add a new row to the NEWDEPT table. Use this INSERT statement:

 INSERT INTO NEWDEPT (DEPTNO, DEPTNAME, MGRNO, ADMRDEPT)
   VALUES ('E31', 'PUBLISHING', '000020', 'D11'); 

After inserting the new department row into the NEWDEPT table, you can use a SELECT statement to see what the modified table looks like. Use this query:

SELECT *
  FROM NEWDEPT
  WHERE DEPTNO LIKE 'E%'
  ORDER BY DEPTNO;

The result table gives you the new department row that you inserted for department E31 and the existing departments with a department number beginning in E.

DEPTNO     DEPTNAME             MGRNO      ADMRDEPT
======     ================     ======     ========
E21        SOFTWARE SUPPORT     ------          D11
E31        PUBLISHING           000020          D11      




Copyright IBM Corporation 1990, 2010