Академический Документы
Профессиональный Документы
Культура Документы
Attributes: properties of entity sets, which associate each entity in the set with a value in a domain of values for that attribute
social security number, name, address, occupation, employer domain of values: integers, dates, strings, etc
Keys: one or more attributes that uniquely identify an entity in the set Isa hierarchies: A isa B (read A is a B), if entity set B is a generalization of entity set A, or, equivalently B is a special kind of A.
The primary purpose of defining isa hierarchies between two sets is so that one can inherit the attributes of the other an employee is a person, the claimant is a person
Phone
EMPS
DEPTS
Manages
MANAGERS
Name
Location
Name
PERSONS
projection
12
selection
select name from customers where balance < 0 select distinct location from suppliers
projection + selection
set
13
Join (equijoin)
select c1.name, c2.addr from customers c1, customers c2 where c1.balance < c2.balance and c2.name = Dimitra
Tuple variables
14
Pattern matching
System Functions
15
16
renaming
renaming
Group selection
18
SQL: Insert
insert into suppliers values (Ajax, Escargot, 24) must give all the values in the same order as defined in the table
insert into suppliers (Name, item, price) values (Ajax, Escargot, 24)
insert into acme_sells select item, price from supplies where name=acme
SQL: Delete
Delete from R Where <condition> Generic form
selection
Delete from orders Where order_num in (select order_num from includes where item = Brie)
20
SQL: Update
update R set A1=E1, Ak=Ek where <condition> generic form
group update
21
Create table supplies (name char(20) not null, item char(10) not null, price number (6,2))
Drop table R
Deletes a table
Drop table supplies
22
ER Diagram
Relational Model
SQL Tables
Relational Algebra
SQL
23
supplier (sname, address, item, price) Redundancy the address of the supplier is repeated once for each item Potential inconsistency (update anomalies) if we update the address of a supplier in one record, we must make sure we update it in all the records Insertion anomalies we cannot record the address of a supplier if that supplier does not currently have at least one item Deletion anomalies if we delete all the items supplied by a supplier, we unintentionally loose track of the suppliers address supplier (sname, address) supplies (sname, item, price)
A better design (?)
24
Functional Dependencies
Constraints that depend only on the equality or inequality of values
Let R(A1,...An) be a relation, and let X and Y be subsets of {A1,..An}. We say X->Y, read X functionally determines Y or Y functionally depends on X if, it is not possible for R to have two tuples that agree on X but not on Y Example {sname}->{address} Another way to say this is: if you know the value of X, then you know (i.e., you can determine) the value of Y
Integrity constraints are not functional dependencies (example integrity constraints: no one with an employment history of 37 years is 27 years old, no one is 60 feet tall, etc)
26
CLAIM TABLE
Claim 1 2 Person Maria Peter Policy_ id Life123 Acc123 Payment 100K 500K
27
Dependency Preservation
If a given database schema satisfies a set of functional dependencies, and the schema is modified, the new schema should also satisfy the same functional dependencies, that is the new schema should not permit invalid data to be added.
supplier (sname, address) supplies (sname, item, price)
then this also satisfies sname->address
SNAME ITEM PRICE
SNAME Acme
ADDRESS 16 River St
Acme
Acme
Brie
Brie
3.49
1.19
29
Dependency Preservation
supplier (sname, address, item, price)
if this satisfies sname->address supplier (sname, item) supplies (sname, address, price) then this does not satisfy sname->address
SNAME Acme
ITEM Brie
SNAM E
Acme Acme
Address
16 River St 123 Main St
PRICE
3.49 1.19
30
31
SNAME
Acme Acme
ITEM
Feta Brie
SNAME
Acme Acme
Address
16 River St 123 Main St
PRICE
3.49 1.19
This is a schema that does not have the loss-less join property can you tell why?
32
Dont Overdo it
person (ssn, name, address, phone) with functional dependencies ssn->name, address, phone
probably not a good idea
person (ssn, name) person (ssn, address) person (ssn, phone) with functional dependencies ssn->name, address, phone
33
Normal Forms
Boyce-Codd normal form (BCNF) Third-Normal form (3NF) BCNF is stronger (i.e., more difficult to achieve) 3NF is an approximation and what appears to be working in practice Every schema in BCNF is also 3NF, but not vice versa, i.e., 3NF permits data relationships that are disallowed by BCNF
34
BCNF
Not in BCNF!
loan (branch, customer, loan_num, amount) with loan_num -> amount, branch
35
36
3NF simplified
First rule of normal form
remove redundant data from horizontal rows; all data should be held in columns and rows
37