Professional Documents
Culture Documents
02 Rmodel
02 Rmodel
relation schema:
¾ Students(sid: string, name: string, login: string, age: integer, gpa: real)
relation instance:
A database schema :
¾ Employees(ssn: char(11), name: char(30), lot: integer)
¾ Departments(did: integer, dname: char(20), budget: real)
¾ Works_in(ssn: char(11), did: integer, since: date)
A database instance :
Databases are created and updated by the DBA with the use of a
Data Definition Language (DDL)
¾ SQL (pronounced Se-Qu-El or Es-Qu-El) is the dominant DDL used
by all commercial DBMSs
¾ SQL is also a DML (data manipulation language)
More on DML features of SQL next week
How to create a table in SQL:
¾ CREATE TABLE Employees
(ssn CHAR(11), An empty table with no tuples is the
name CHAR(30), instance of relation Employees
lot INTEGER)
How to destroy a table: The schema and the instance of the relation
¾ DROP TABLE Employees are deleted from the DBMS
How to alter the schema of a table:
¾ ALTER TABLE Employees For each tuple in the instance of
ADD COLUMN address CHAR(40) Employees a null value is added
for the new attribute
13-324 Jones 22
Works_in
Employees Departments
ssn did since
Works_in
Employees Departments
ssn did since
Q1. What will happen if an Employees tuple is deleted and its ssn
appears in some tuples of Works_in?
Q2. What will happen if an Employees tuple is updated and its previous
ssn value appears in some tuples of Works_in?
Q3. What will happen if a Departments tuple is deleted and its did
appears in some tuples of Works_in?
Other:
¾ ON DELETE SET DEFAULT
¾ ON DELETE SET NULL
Intro. to Dababase Management Systems 3.18 Lecture notes by Nikos Mamoulis
More Constraints
Employees
Works_in
since
Intro. to Dababase Management Systems 3.27 Lecture notes by Nikos Mamoulis
Translating Weak Entities
Similar to total participation + key constraint case, however, we also
need to consider the partial key and the weak entity dependence
CREATE TABLE Dep_Policy
Include the primary key of
(pname CHAR(20), Employees as attribute
age INTEGER,
Use primary key of
cost REAL, Employees + partial key as
ssn CHAR(11), the primary key of relation
PRIMARY KEY(pname,ssn),
FOREIGN KEY(ssn) REFERENCES Employees
propagate the deletion of
ON DELETE CASCADE) an employee to the
deletion of its dependents
Employees Dependants
Purchaser beneficiary
Employees
supervisor sub-ordinate
ER diagram B
Reports_to