Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.

Similar presentations


Presentation on theme: "Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1."— Presentation transcript:

1 Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1

2 Learning Objectives  Explain the importance and advantages of databases.  Describe the difference between database systems and file- based legacy systems.  Explain the difference between logical and physical views of a database.  Explain fundamental concepts of database systems such as DBMS, schemas, the data dictionary, and DBMS languages.  Describe what a relational database is and how it organizes data.  Create a set of well-structured tables to store data in a relational database.  Perform simple queries using the Microsoft Access database. Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-2

3 Data Hierarchy  Field  Attributes about an entity  Record  Related group of fields  File  Related group of records  Database  Related group of files Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-3

4 Advantages of Database Systems  Data Integration  Files are logically combined and made accessible to various systems.  Data Sharing  With data in one place it is more easily accessed by authorized users.  Minimizing Data Redundancy and Data Inconsistency  Eliminates the same data being stored in multiple files, thus reducing inconsistency in multiple versions of the same data. Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-4

5 Advantages of Database Systems  Data Independence  Data is separate from the programs that access it. Changes can be made to the data without necessitating a change in the programs and vice versa.  Cross-Functional Analysis  Relationships between data from various organizational departments can be more easily combined. Copyright 2012 © Pearson Education, Inc. publishing as Prentice Hall 4-5

6 Database Terminology  Database Management System (DBMS)  Interface between software applications and the data in files.  Database Administrator (DBA)  Person responsible for maintaining the database  Data Dictionary  Information about the structure of the database  Field names, descriptions, uses Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-6

7 Logical vs. Physical  Physical View  Depends on explicitly knowing:  How is the data actually arranged in a file  Where is the data stored on the computer  Logical View  A Schema separates storage of data from use of the data  Unnecessary to explicitly know how and where data is stored. Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-7

8 Schemas  Describe the logical structure of a database  Conceptual Level  Organization wide view of the data  External Level  Individual users view of the data  Each view is a subschema  Internal Level  Describes how data are stored and accessed  Description of: records, definitions, addresses, and indexes Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-8

9 Subschema--User ASubschema--User B Subschema--User C Enroll Cash Receipt ClassesStudent Mapping external-level views to conceptual-level schema Mapping conceptual-level items to internal-level descriptions Smith... A Jones... B Arnold...D

10 DBMS Languages  Data Definition Language (DDL)  Builds the data dictionary  Creates the database  Describes the subschema  Specifies record or field security constraints  Data Manipulation Language (DML)  Changes the content in the database  Updates, insertions, and deletions Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-10

11 DBMS Languages  Data query language (DQL)  Enables the retrieval, sorting, and display of data from the database  SQL (structured query language) is the standard DQL  Example: SELECT Customer.CustName FROM Customer, Sales WHERE Customer.CustNo = Sales.CustNo AND Sales.Salesperson = “Martinez”  Report writer 4-11

12 Relational Database  Relational data model represents the conceptual and external level schemas as if data are stored in tables.  Table  Each row, a tuple, contains data about one instance of an entity.  This is equivalent to a record  Each column contains data about one attribute of an entity.  This is equivalent to a field Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-12

13 A Relational Table Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-13 Row (Record) Column (Field) Each row contains multiple attributes describing an instance of the entity. In this case, inventory. Same type of data

14 Attributes  Primary Key  An attribute or combination of attributes that can be used to uniquely identify a specific row (record) in a table.  Foreign Key  An attribute in one table that is a primary key in another table.  Used to link the two tables Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-14

15 Database Design Errors  If database is not designed properly data errors can occur.  Update Anomaly  Changes to existing data are not correctly recorded.  Due to multiple records with the same data attributes  Insert Anomaly  Unable to add a record to the database.  Delete Anomaly  Removing a record also removes unintended data from the database. Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-15

16 Student ID Last Name First NamePhone No.Course No. Sectio nDayTime 333-33-3333SimpsonAlice333-3333ACCT-36031M9:00 AM 333-33-3333SimpsonAlice333-3333FIN-32133Th11:00 AM 333-33-3333SimpsonAlice333-3333MGMT-302111TH12:00 PM 111-11-1111SandersNed444-4444ACCT-34332T10:00 AM 111-11-1111SandersNed444-4444MGMT-30215W8:00 AM 111-11-1111SandersNed444-4444ANSI-14227F9:00 AM 123-45-6789MooreArtie555-5555ACCT-34332T10:00 AM 123-45-6789MooreArtie555-5555FIN-32133Th11:00 AM Database Design Errors

17 Student ID Last Name First NamePhone No.Course No.Sect.DayTime 333-33-3333SimpsonAlice333-3333ACCT-36031M9:00 AM 333-33-3333SimpsonAlice333-3333FIN-32133Th11:00 AM 333-33-3333SimpsonAlice333-3333MGMT-302111TH12:00 PM 111-11-1111SandersNed444-4444ACCT-34332T10:00 AM 111-11-1111SandersNed444-4444MGMT-30215W8:00 AM 111-11-1111SandersNed444-4444ANSI-14227F9:00 AM 123-45-6789MooreArtie555-5555ACCT-34332T10:00 AM 123-45-6789MooreArtie555-5555FIN-32133Th11:00 AM Suppose Alice Simpson changes her phone number. You need to make the change in three places. If you fail to change it in all three places or change it incorrectly in one place, then the records for Alice will be inconsistent. This problem is referred to as an update anomaly.

18 Student ID Last Name First NamePhone No.Course No.Sect.DayTime 333-33-3333SimpsonAlice333-3333ACCT-36031M9:00 AM 333-33-3333SimpsonAlice333-3333FIN-32133Th11:00 AM 333-33-3333SimpsonAlice333-3333MGMT-302111TH12:00 PM 111-11-1111SandersNed444-4444ACCT-34332T10:00 AM 111-11-1111SandersNed444-4444MGMT-30215W8:00 AM 111-11-1111SandersNed444-4444ANSI-14227F9:00 AM 123-45-6789MooreArtie555-5555ACCT-34332T10:00 AM 123-45-6789MooreArtie555-5555FIN-32133Th11:00 AM What happens if you have a new student to add, but he hasn’t signed up for any courses yet? Or what if there is a new class to add, but there are no students enrolled in it yet? In either case, the record will be partially blank. This problem is referred to as an insert anomaly.

19 Student ID Last Name First NamePhone No.Course No.Sect.DayTime 333-33-3333SimpsonAlice333-3333ACCT-36031M9:00 AM 333-33-3333SimpsonAlice333-3333FIN-32133Th11:00 AM 333-33-3333SimpsonAlice333-3333MGMT-302111TH12:00 PM 111-11-1111SandersNed444-4444ACCT-34332T10:00 AM 111-11-1111SandersNed444-4444MGMT-30215W8:00 AM 111-11-1111SandersNed444-4444ANSI-14227F9:00 AM 123-45-6789MooreArtie555-5555ACCT-34332T10:00 AM 123-45-6789MooreArtie555-5555FIN-32133Th11:00 AM If Ned withdraws from all his classes and you eliminate all three of his rows from the table, then you will no longer have a record of Ned. If Ned is planning to take classes next semester, then you probably didn’t really want to delete all records of him. This problem is referred to as a delete anomaly.

20 Design Requirements for DBs 1.Every column must be single valued. 2.Primary keys must contain data (not null). 3.Foreign keys must contain the same data as the primary key in another table. 4.All other attributes must identify a characteristic of the table identified by the primary key. Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-20

21 Normalizing Relational Databases  Initially, one table is used for all the data in a database.  Following rules, the table is decomposed into multiple tables related by:  Primary key–foreign key integration  Decomposed set of tables are in third normal form (3NF). Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-21


Download ppt "Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1."

Similar presentations


Ads by Google