Inserting Data
Before a database can be really of any use, data must be inserted into it by some means, either by manual data entry or with an automated batch loading program. The action of inserting data only applies to cases in which you wish to load a completely new record of information into the database. If the record already exists and merely requires modification of a column value, the update operation should be used instead.
Data inserts in the relational database model are done on a row-by-row basis: each record or item of information that you load into the database corresponds to a brand-new row within a given existing table. As each inserted record corresponds to a new row in one table, multitable inserts are not possible.[28]
The SQL INSERT
keyword
provides a simple mechanism for inserting new rows of data into the
database. For example, assuming the megaliths
table is already present in the database and and contains the six
columns shown earlier in Figure 3.1, a single row
of data can be inserted into it using the following SQL statement:
INSERT INTO megaliths VALUES ( 0, 'Callanish I',
'"Stonehenge of the North"',
'Western Isles',
'NB 213 330', 1 )If you then SELECT back all the rows in the table,
you should be able to see the row that has just been inserted.
Just as the SELECT statement could specify which columns from a table should be returned in the query, it is also possible (and good practice) to specify into which columns of the table the values should be inserted. ...