Professional Documents
Culture Documents
9 - SQL Nested Clause-Select-From Part - 5of5
9 - SQL Nested Clause-Select-From Part - 5of5
or equivalently
update instructor
set salary = case
when salary <= 100000 then
salary * 1.05
else salary * 1.03
end
Updates with Scalar Subqueries
Recompute and update tot_creds value for all students
update student S
set tot_cred = (select sum(credits)
from takes, course
where takes.course_id =
course.course_id and
S.ID= takes.ID.and
takes.grade <> ’F’ and
takes.grade is not null);
Sets tot_creds to null for students who have not taken
any course
Instead of sum(credits), use:
case
when sum(credits) is not null then
sum(credits)
else 0
end
VIEW
In SQL, a view is a virtual table that contains
data from one or more tables. It has rows and
columns, similar to a real table. Views are a
special version of tables in SQL, providing a
virtual table environment for various complex
operations.
Unlike a physical table, a view does not store the
data itself but provides a way to represent the
data stored in one or more underlying tables in a
specific way. Views are used to simplify complex
queries, encapsulate complex logic, and provide
a layer of abstraction between the database
schema and the users or applications interacting
with the database.
CHARACTERISTICS OF VIEW
database.
CREATE TABLE employees (
employee_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
department VARCHAR(50)
);
SQL AS DDL contt…
FROM user1;
End