Chapter 6
Chapter 6
▪ 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
▪ Database schema
Simple syntax: CREATE DATABASE dbname
▪ Add/remove constraints
ALTER TABLE tablename
ADD CONSTRAINT constraintName PRIMARY KEY
(<attribute list>);
SELECT L
FROM R πL(σC(R))
WHERE C
Example 5.1:
◦ Find all employees named as ‘Võ Việt Anh’
Example 5.2
◦ Find all employees whose name is ended at
‘Anh’
x y x AND y x OR y NOT x
TRUE TRUE TRUE TRUE FALSE
TRUE UNKNOWN UNKNOWN TRUE FALSE
TRUE FALSE FALSE TRUE FALSE
UNKNOWN TRUE UNKNOWN TRUE UNKNOWN
UNKNOWN UNKNOWN UNKNOWN UNKNOWN UNKNOWN
UNKNOWN FALSE FALSE UNKNOWN UNKNOWN
FALSE TRUE FALSE TRUE TRUE
FALSE UNKNOWN FALSE UNKNOWN TRUE
FALSE FALSE FALSE FALSE TRUE
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
Example 15.1
◦ Find departments and employees who work in
those departments, respectively
A B
NULL NULL
Syntax: