Professional Documents
Culture Documents
Views in SQL: No Limitation On Querying A View
Views in SQL: No Limitation On Querying A View
Views in SQL: No Limitation On Querying A View
HardClimbs:
Route Rating FeetHigh
SlimyClimb 9 200
Modifying tuples
• Non-key values of a relation can be changed using
UPDATE.
• Suppose we want to increase the age of all
experienced climbers by 1:
UPDATE Climbers
SET Age = Age+1
WHERE Skill = “EXP”;
• NOTE: SQL uses an “old-value” semantics. New values
are calculated using the old state, not a partially
modified state.
Old-value semantics
• “Give a $1000 raise to every employee who earns
less than their manager.”
Emp Manager Salary
1 3 20,000
2 3 21,500
3 21,000
• Old-value semantics: employees 1 and 3 are given
a raise.
• Otherwise: employee 2 will get a raise if they are
considered after employee 3 receives a raise!
Schema modification
• Requirements change over time, so it is
useful to be able to add/delete columns,
drop tables and drop views:
– DROP TABLE Climbers;
– DROP VIEW ExpClimbers;
– ALTER TABLE Climbs ADD Weather
CHAR(50);
– ALTER TABLE Routes DROP Grade;
Summary
• Views are useful for frequently executed
queries and as a layer to shield applications
from changes in the schema.
• SQL has an update language that allows set-
oriented updates. Updates (insertions,
deletions and modifications) change the
database state.