Professional Documents
Culture Documents
lawrence snyder
14-2
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
The Database's Advantage
14-3
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Tables and Entities
14-4
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Entities
14-5
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
14-6
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Entities (cont'd)
• Entity instances
– Rows of data
• Table instance
– Any table containing specific rows
• Attributes have a data type
– Defines the form of the information that can be
stored in a field
• Number, text, image, …
<name type="text"> <area type="number">
14-7
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Properties of Entities
14-8
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Properties of Entities (cont'd)
• Uniqueness
– No two rows can be the same
– Two rows can have the same value for
some attributes, just not all attributes
14-9
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Properties of Entities (cont'd)
• Keys
– Any set of attributes for which all attribute values
are different is called a candidate key
– Pick one and call it the primary key to decide
uniqueness
– Key must distinguish all potential and actual
entities, not just those that happen to be in the
table at a given time
– If no combination of attributes qualify as a
candidate key, assign a unique ID to each entity
• Like a student ID number issued by school
14-10
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Properties of Entities (cont'd)
• Atomic Data
– Values stored for attributes
– Not decomposable into any smaller parts
• Separate fields for street, city, state, postal
code
– "Only atomic data" rule relaxed for certain
types of data
• Dates, times, currency
14-11
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Database Schemes
14-12
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Spreadsheets and Entities
14-14
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Operations on Tables
14-15
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
14-16
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Select Operation
• Takes rows from one table to create a new
table
– Specify the table from which rows are to be taken,
and the test for selection
– Syntax: Select Test From Table
• Test is a formula combining attribute names, constants,
and relational operators
– Test is applied to each rows of the table to
determine if it should be included in result table
• If the test is true for a given row, the row is included in the
result table; otherwise it is ignored
Select Interest='Beach' From Nations
14-17
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Select Interest='Beach' From Nations
14-18
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Project Operation
14-19
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Example:
Project Name, Domain, Interest From Nations
14-20
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Project Operation (cont'd)
14-21
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Example:
Project Name, Domain, Latitude From
(Select Latitude >= 60 AND N_S='N' From Nations)
14-22
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Union Operation
14-23
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Example:
ExtremeGovt = At60OrAbove + At45OrBelow
14-24
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Difference Operation
14-25
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Join Operation
14-26
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Join Operation
14-27
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Join Operation (cont'd)
14-28
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Join Operation Applied
Consider the tableNorthern = (Project Name, Domain,
Latitude From At60orAbove)
14-29
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Join Applied
14-30
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Join Applied (cont'd)
14-32
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
14-33
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Physical and Logical Databases
14-34
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Physical Database
14-35
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Logical Database
14-36
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Queries
14-37
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Defining Physical Tables
14-38
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
14-39
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
14-40
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Connecting Database Tables by
Relationships
• Student and Home_Base tables
– The tables can have different security
access restrictions based on their data
• Other units can access Home_Base data
without having access to more sensitive data
in Student
– Separate tables but not independent
• Student_ID connects the two tables
(establishes a relationship between them)
– Primary key
14-41
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
The Idea of Relationship
• Relationship examples
Father_of, relationship between man and child
Daughter_of, relationship between girl and parents
Employed_by, between people and companies
Stars_in, relationship between actors and movies
• A DB relationship is a correspondence
between rows of one table and the
rows of another table
14-42
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Relationships in Practice
• Key Student_ID is used in each table
• We can find the address for each student (Lives_At),
and also the student for each address (Home_Of)
14-43
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Defining Logical Tables
Build with Join, Match on the common field Student_ID
Master_List = Student Home_Base
On Student.Student_ID = Home_Base.Student_ID
14-44
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Practical Construction Using QBE
• Query By Example
– Given a template of a table we fill in what we
want in the fields
14-45
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Query was generated by this dialog:
14-46
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
The Dean's View
• Storing the Dean's Data
– Top_Scholar is information of interest only to the dean
14-47
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Creating a Dean's View
14-48
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Join Three Tables into One
Dean_Data_Collect = ( Top_Scholar
( Student Home_base
On Student.Student_ID=Home_Base.Student_ID )
On Student.Student_ID=Top_Scholar.Student_ID )
14-49
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Join Three Tables into One
14-50
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
14-51
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Summary
14-52
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Summary
14-53
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Summary
14-54
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley