chapter 2 part 1(database system)
TRANSCRIPT
By the end of this lesson, student will be able to:
2.1 Define database
2.2 Describe components of a database table
2.3 Describe the characteristics of relation scheme
2.4 Identify relation keys
2.5 Explain integrity rules
2.6 Explain relational model relationships
Database• A collection of related data• Shared collection of logically related data (and a description
of this data), designed to meet the information needs of an organization.
Data Known facts that can be recorded and have an implicit
meaning/ Raw facts; that is, facts that have not been yet processed to reveal their meaning to the end user.
Information Facts (data) that are arranged in meaningful patterns
Relational database is a collection of tables
Heading: table name and column names
Body: rows, occurrences of data
StdSSN StdLastName StdMajor StdClass StdGPA 123-45-6789 WELLS IS FR 3.00 124-56-7890 NORBERT FIN JR 2.70 234-56-7890 KENDALL ACCT JR 3.50
Student
• Typically include: 1) Numeric data types for integers and real numbers2) Characters3) Booleans4) Fixed-length strings5) Variable-length strings6) Date, time, timestamp7) Money / Currency8) Other special data types
Marina G. Erechtchoukova 8
Schema:Book (Bid: char(2), Title: char(50),
Author:char(20), Price: decimal(5,2)) Instance: Bid Title Author Price
11 Franklin forgets Bourgeois 7.00
22 Arthur and the Seventh-Inning Stretcher Krensky 14.00
33 Midnight Wrestlers Morgan 11.00
44 Midnight Pilot Morgan 9.00
55 Book of Science Activities 18.00
Yards
Yard Number
Owner
Address
Phone Number
1 2
3
4
1) What is the name of the relation?2) What is the cardinality of the relation?3) What is the degree of the relation?4) What is the domain of StdGPA? What is the
domain of StdSSN?
StdSSN StdLastName StdMajor StdClass StdGPA 123-45-6789 WELLS IS FR 3.00 124-56-7890 NORBERT FIN JR 2.70 234-56-7890 KENDALL ACCT JR 3.50
Student
Answer the question below based on the following tables:
LECTURER
Identify attribute, domain, tuple, and cardinality
StaffNum ICNum Name Posit ion Department PhoneNumIT001 781103-03-5333 Abdullah Pensyarah Kejuruteraan perisian 09-8840023
IT002 680923-11-4908 Maimunah Prof Madya Sains komputer 09-8840024IT003 801204-06-2323 Kamal Pensyarah Sistem maklumat 09-8840025IT004 600720-06-5380 Jamilah Prof Madya Multimedia 09-8840026IT005 590101-01-2425 Hakim Professor Kejuruteraan perisian 09-8840027IT006 810303-19-9923 Anis Pensyarah Multimedia 09-8840028
LECTURER
GRADE STUDENT
1) Identify attribute, domain, tuple, degree and cardinality for table GRADE & STUDENT.
2) Transform each table to relation schema.
StudentNum CourseCod
e
Grade
P1050 SK001 2.50
L2115 SM100 3.00
L4213 KP222 3.00
P2020 SM100 3.50
StudentNum Name CourseCode
P1050 Azura SK001
L2115 Chong SM100
L4213 Karim KP222
P2020 Ahmad SM100
1) Candidate key- Any set of one or more columns whose combined values are
unique among all occurrences (i.e., tuples or rows). - Since a null value is not guaranteed to be unique, no
component of a candidate key is allowed to be null. - There can be any number of candidate keys in a table .
2) Primary key- Any candidate key of that table which the database designer
arbitrarily designates as "primary".- The primary key may be selected for convenience,
comprehension, performance, or any other reasons.
3) Foreign key- A set of one or more columns in any table which may hold
the value(s) found in the primary key column(s) of some other table.
1) What is the candidate key ?2) What is the primary key?3) Transform the table to relation schema.
Identify the relational key available in each relation.
Data integrity means that the data values in the database are correct and consistent.
Integrity constraints provide a way of ensuring that changes made to the database by authorized users do not result in a loss of data consistency
Data integrity is enforced in the relational model by:
1) Entity integrity
2) Referential integrity
Entity Integrity- The entity integrity rule states that for every instance of an
entity, the value of the primary key must exist, be unique, and cannot be null.
- Without entity integrity, the primary key could not fulfill its role of uniquely identifying each instance of an entity.
Referential Integrity- The referential integrity rule states that every foreign key
value must match a primary key value in an associated table.
- Referential integrity ensures that we can correctly navigate between related entities.
1) One to many2) Many to many3) Self referencing
• One Birdfeeder is visited by Many Birds• One Yard contains Many Birdfeeders• One Patient has Many Prescriptions• One Insurance has Many Patients• One Student attends Many Classes
• One to Many relationships are the most common relationships.
• A record MUST be in the One table in order to appear in the Many table.
• One to Many includes One to None.
1 ∞Medical Record #
Patients Prescription Number
Medical Record #
Medications
Primary Key linked to Non Primary Key
Example 1:
Bird Feeders
Bird Feeder Number
Material
Location in Yard
Yard Number
Yards
Yard Number
Owner
Address
Phone Number
Each Birdfeeder can only be in one Yard, but each Yard can have many Birdfeeders. This is called a one to many (1 - ∞) Relationship.
• Many Students are taught by Many Teachers• Many Patients see Many Doctors• Many Medications are taken by Many Patients• Many Customers buy Many Products
Many to Many relationships are also very common.
∞ ∞Shands Medical Record #
Medicare Patients Prescription Number
Shands Medical Record #
Medications
Non Primary Key linked to Non Primary Key
Example:
Access sees this as an Indeterminate relationship
You cannot Enforce Referential Integrity
Indeterminate relationships are often found when we are linking tables, because Linked Tables cannot have a primary key.
If you have imported or created a table, it’s very rare to have a need for an indeterminate Relationship.
These relationships show Access that the data saved in the field from the first table is the same kind of data saved in the second table, but there can be no data integrity rules applied on indeterminate relationships.
ExamplesPatients
Patient ID
First
Last
Address
City
State
Zip
Medications
Med ID
Medication
Description
Patient Meds
PM ID
Patient ID
Med ID
Dosage
Directions
1
One Patient can take many
Medications∞
1
One Kind of Medication can be
taken by Many Patients
∞
ExamplesPatients
Patient ID
First
Last
Address
City
State
Zip
Primary Drs
Doc ID
Name
Phone
Pager
ExamplesPatients
Patient ID
First
Last
Address
City
State
Zip
Primary Drs
Doc ID
Name
Phone
Pager
One Patient will have only ONE primary Doctor.One Primary Doctor can have MANY patients.
Primary Doc
1
∞
ExamplesPatients
Patient ID
First
Last
Address
City
State
Zip
Med History
Patient ID
Health Q1
Health Q2
Health Q3
Health Q4
ExamplesPatients
Patient ID
First
Last
Address
City
State
Zip
Med History
Patient ID
Health Q1
Health Q2
Health Q3
Health Q4
One Patient will have only ONE Medical History.Each Medical History will belong to only ONE patient.
11