中文网站
  Advanced Search
Read the latest Blogs from IT professionals in the field. Read and write community created documents. Need IT help? Ask our staff. Connect with your peers. Check our Tech Shop for posters, books and software tools. Home

4.8.2 Database Systems: Insertion

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:
(a) 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)

(b) 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 in nite number of tuples. Evaluating the select statement completely before performing
insertions avoids such problems.

(c) 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.

Database System Structure: