Database Modification

This section deals with the insertion, updation and deletion of records from the database.

Insertion

Insert values into a relation using:

insert into r values (V1, V2, ..., Vn)

We can also insert the results of a select query into a relation (if there are no errors in the result of the query)

insert into r select attributes from s where P

Updation

This is used to update existing records.

update r set attribute=new_value where P

case statements can be used for conditional updates, as shown in the example below:

update instructor
 set salary = case
               when salary <= 100000 then salary * 1.05
               else salary * 1.03
              end

Deletion

To delete all records, use:

delete from r

To delete specific records, use:

delete from r where P

Last updated