next up previous
Next: Updates Up: Modification of the Database Previous: Deletion


  1. To insert data into a relation, we either specify a tuple, or write a query whose result is the set of tuples to be inserted. Attribute values for inserted tuples must be members of the attribute's domain.
  2. Some examples:
    1. To insert a tuple for Smith who has $1200 in account A-9372 at the SFU branch.

       insert into account

      values (``SFU'', ``A-9372'', 1200)

    2. To provide each loan that the customer has in the SFU branch with a $200 savings account.

       insert into account

      select bname, loan#, 200

      from loan

      where bname=``SFU''

      Here, we use a select to specify a set of tuples.

      It is important that we evaluate the select statement fully before carrying out any insertion. If some insertions were carried out even as the select statement were being evaluated, the insertion

       insert into account

      select *

      from account

      might insert an infinite number of tuples. Evaluating the select statement completely before performing insertions avoids such problems.

    3. It is possible for inserted tuples to be given values on only some attributes of the schema. The remaining attributes are assigned a null value denoted by null.

      We can prohibit the insertion of null values using the SQL DDL.

Osmar Zaiane
Fri May 22 19:39:12 PDT 1998