Chapter 2 part 1(Database System)


Published on

Chapter 2 Part 1 Database System :)

Published in: Education, Technology, Business
1 Comment
1 Like
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Chapter 2 part 1(Database System)

  1. 1. 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
  2. 2. 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
  3. 3. Relational database is a collection of tables  Heading: table name and column names  Body: rows, occurrences of data  Student StdSSN 123-45-6789 124-56-7890 234-56-7890 StdLastName WELLS NORBERT KENDALL StdMajor IS FIN ACCT StdClass FR JR JR StdGPA 3.00 2.70 3.50
  4. 4. • Typically include: 1) Numeric data types for integers and real numbers 2) Characters 3) Booleans 4) Fixed-length strings 5) Variable-length strings 6) Date, time, timestamp 7) Money / Currency 8) Other special data types
  5. 5. 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 Marina G. Erechtchoukova 8
  6. 6. 2 1 3 4 Yards Yard Number Owner Address Phone Number
  7. 7. Student StdSSN 123-45-6789 124-56-7890 234-56-7890 StdLastName WELLS NORBERT KENDALL StdMajor IS FIN ACCT StdClass FR JR JR StdGPA 3.00 2.70 3.50 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?
  8. 8. LECTURER Answer the question below based on the following tables: LECTURER StaffNum ICNum IT001 781103-03-5333 Name Abdullah Position Pensyarah Department PhoneNum Kejuruteraan perisian 09-8840023 IT002 IT003 IT004 IT005 IT006 Maimunah Kamal Jamilah Hakim Anis Prof Madya Pensyarah Prof Madya Professor Pensyarah Sains komputer Sistem maklumat Multimedia Kejuruteraan perisian Multimedia 680923-11-4908 801204-06-2323 600720-06-5380 590101-01-2425 810303-19-9923 09-8840024 09-8840025 09-8840026 09-8840027 09-8840028 Identify attribute, domain, tuple, and cardinality
  9. 9. GRADE StudentNum STUDENT CourseCod Grade StudentNum Name CourseCode e P1050 SK001 2.50 P1050 Azura SK001 L2115 SM100 3.00 L2115 Chong SM100 L4213 KP222 3.00 L4213 Karim KP222 P2020 SM100 3.50 P2020 Ahmad SM100 1) Identify attribute, domain, tuple, degree and cardinality for table GRADE & STUDENT. 2) Transform each table to relation schema.
  10. 10. 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.
  11. 11. 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.
  12. 12. 1) What is the candidate key ? 2) What is the primary key? 3) Transform the table to relation schema.
  13. 13. Identify the relational key available in each relation.
  14. 14.  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: Entity integrity Referential integrity 1) 2)
  15. 15. 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.
  16. 16. 1) 2) 3) One to many Many to many Self referencing
  17. 17. • One to Many relationships are the most common relationships. • • • • • • 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 includes One to None. • A record MUST be in the One table in order to appear in the Many table.
  18. 18. Primary Key linked to Non Primary Key Example 1: Medications Patients Medical Record # 1 ∞ Prescription Number Medical Record #
  19. 19. Bird Feeders Yards Bird Feeder Number Yard Number Material Owner Location in Yard Address Yard Number 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.
  20. 20. Many to Many relationships are also very common. • Many Students are taught by Many Teachers • Many Patients see Many Doctors • Many Medications are taken by Many Patients • Many Customers buy Many Products
  21. 21. Non Primary Key linked to Non Primary Key Example: Medications Medicare Patients Shands Medical Record # ∞ ∞ Prescription Number Shands Medical Record # Access sees this as an Indeterminate relationship You cannot Enforce Referential Integrity
  22. 22. 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.
  23. 23. Examples Patients Patient ID First Last Address City State Zip One Patient can take many Medications 1 1 ∞ Patient Meds PM ID Patient ID Med ID Dosage Directions ∞ Medications Med ID Medication Description One Kind of Medication can be taken by Many Patients
  24. 24. Examples Patients Patient ID First Last Address City State Zip Primary Drs Doc ID Name Phone Pager email
  25. 25. Examples Patients Patient ID First Last Address City State Zip Primary Doc 1 ∞ Primary Drs Doc ID Name Phone Pager email One Patient will have only ONE primary Doctor. One Primary Doctor can have MANY patients.
  26. 26. Examples Patients Patient ID First Last Address City State Zip Med History Patient ID Health Q1 Health Q2 Health Q3 Health Q4
  27. 27. Examples Patients Patient ID First Last Address City State Zip 1 Med History 1 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.