Sei sulla pagina 1di 1

Chapter 2

Inserting
2.1 Introduction
The second step in the life cycle of a relational database, after creating the
tables, is to populate those tables with data. SQL Anywhere offers three distinct
techniques: the INSERT, LOAD TABLE, and ISQL INPUT statements.
The INSERT statement comes in two flavors, depending on whether you
want to explicitly provide VALUES for each column, one row per INSERT, or
to copy an entire set of rows into a table from some other source with a single
INSERT, where the other source is anything a SELECT can produce.
Those two flavors of INSERT are broken down further in this chapter, into
five separate formats depending on whether values are provided for some or all
of the target tables columns and whether the AUTO NAME feature is used.
LOAD TABLE and ISQL INPUT provide two different ways to insert data
into a table from an external file.
Each of these techniques offer interesting features discussed in this chapter.
For example, the ON EXISTING UPDATE clause lets you turn an INSERT into
an UPDATE when primary keys collide, LOAD TABLE takes dramatic short-
cuts to offer better performance, and the ISQL INPUT statement can be used to
load fixed-layout records and other file formats from legacy sources.

2.2 INSERT
The INSERT statement comes in five different formats, discussed in the next
five sections:
n INSERT a single row using a VALUES list for all the columns.
n INSERT a single row using a column name list and matching VALUES list.
n INSERT multiple rows using a SELECT to retrieve values for all the
columns.
n INSERT multiple rows using a column name list and a matching SELECT.
n INSERT multiple rows using the WITH AUTO NAME clause instead of a
column name list.

49

Potrebbero piacerti anche