The Database Language SQL
The Database Language SQL
▪ Integrity constraints
▪ Structure Query Language
▪ DDL
▪ DML
▪ DCL (self studying)
▪ Sub query
Getting Relational
User High-Level Database Relational
Requiremen Design Schema DBMS
t Design
COMPANY Database
x y x AND y x OR y NOT x
TRUE TRUE TRUE TRUE FALSE
TRUE UNKNOW UNKNOW TRUE FALSE
N N
TRUE FALSE FALSE TRUE FALSE
UNKNOW TRUE UNKNOW TRUE UNKNOW
N N N
UNKNOW UNKNOW UNKNOW UNKNOW UNKNOW
N N N N N
UNKNOW FALSE FALSE UNKNOW UNKNOW
N N N
FALSE TRUE FALSE TRUE TRUE
FALSE UNKNOW FALSE UNKNOW TRUE
N THE DATABASE LANGUAGE SQL N 13
The Truth-Value Unknown
SQL conditions in Where clause produce three
truth values: True, False, and Unknown
Those tuples which condition has the value True
become part of the answer
Those tuples which condition has the value False
or Unknown are excluded from the answer
▪Add/remove constraints
ALTER TABLE tablename
ADD CONSTRAINT constraintName PRIMARY KEY
(<attribute list>);
SELECT L
FROM R πL(σC(R))
WHERE C
Example 10.1
◦ Find all those employees whose name is begun
by ‘H’ or salary exceed 80000
Example 10.2
◦ Find all those normal employees, that is who do
not supervise any other employees
Example 10.3
◦ Find all employees who work on projectB and
projectC
Example 11:
◦ Find the employees of Phòng Phần mềm trong
nước department
Example 11:
◦ Find the employees of Phòng Phần mềm trong
nước department
Example 11:
◦ Find the employees of Phòng Phần mềm trong
nước department
Example 12:
◦ Find the dependents of all employees of
department number 1
R UNION ALL S;
R INTERSECT ALL S;
R EXCEPT ALL S;
A B
NULL NULL