Relational Databases Chapter 4.

Slides:



Advertisements
Similar presentations
Relational Database and Data Modeling
Advertisements

CHAPTER OBJECTIVE: NORMALIZATION THE SNOWFLAKE SCHEMA.
Database Systems: Design, Implementation, and Management Tenth Edition
Relational Databases Chapter 4.
© 2006 Prentice Hall Business Publishing Accounting Information Systems, 10/e Romney/Steinbart1 of 95 C HAPTER 4 Relational Databases.
The Relational Database Model:
© 2008 Prentice Hall Business Publishing Accounting Information Systems, 11/e Romney/Steinbart1 of 96 C HAPTER 4 Relational Databases.
© 2008 Prentice Hall Business Publishing Accounting Information Systems, 11/e Romney/Steinbart1 of 96 C HAPTER 4 Relational Databases.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
© 2008 Prentice Hall Business Publishing Accounting Information Systems, 11/e Romney/Steinbart1 of 96 C HAPTER 4 Relational Databases.
Mgt 20600: IT Management & Applications Databases Tuesday April 4, 2006.
Relational Databases Chapter 4.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
Chapter 4 Relational Databases.
Michael F. Price College of Business Chapter 6: Logical database design and the relational model.
Relational Databases Chapter 4.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
Database Technical Session By: Prof. Adarsh Patel.
Concepts and Terminology Introduction to Database.
FILE VS. DATABASES Let’s examine some basic principles about how data are stored in computer systems. – An entity is anything about which the organization.
MIS 301 Information Systems in Organizations Dave Salisbury ( )
I Information Systems Technology Ross Malaga 4 "Part I Understanding Information Systems Technology" Copyright © 2005 Prentice Hall, Inc. 4-1 DATABASE.
©2003 Prentice Hall Business Publishing, Accounting Information Systems, 9/e, Romney/Steinbart 4-1 Accounting Information Systems 9 th Edition Marshall.
Lecture2: Database Environment Prepared by L. Nouf Almujally & Aisha AlArfaj 1 Ref. Chapter2 College of Computer and Information Sciences - Information.
Lecture2: Database Environment Prepared by L. Nouf Almujally 1 Ref. Chapter2 Lecture2.
DataBase Management System What is DBMS Purpose of DBMS Data Abstraction Data Definition Language Data Manipulation Language Data Models Data Keys Relationships.
© 2006 Prentice Hall Business Publishing Accounting Information Systems, 10/e Romney/Steinbart1 of 95 C HAPTER 4 Relational Databases.
CHAPTER 4 Relational Databases. Learning Objectives Explain the importance and advantages of databases Describe the difference between database systems.
©2003 Prentice Hall Business Publishing, Accounting Information Systems, 9/e, Romney/Steinbart 4-1 Relational Databases.
©2003 Prentice Hall Business Publishing, Accounting Information Systems, 9/e, Romney/Steinbart 4-1 Relational Databases.
© 2008 Prentice Hall Business Publishing Accounting Information Systems, 11/e Romney/Steinbart1 of 96 C HAPTER 4 Relational Databases.
Databases Flat Files & Relational Databases. Learning Objectives Describe flat files and databases. Explain the advantages that using a relational database.
ASET 1 Amity School of Engineering & Technology B. Tech. (CSE/IT), III Semester Database Management Systems Jitendra Rajpurohit.
RELATIONAL DATABASES SYSTEMS Unit 3. This unit shift attention to database as an important component of AIS. Understanding the fundamentals of database.
IT 5433 LM3 Relational Data Model. Learning Objectives: List the 5 properties of relations List the properties of a candidate key, primary key and foreign.
© 2006 Prentice Hall Business Publishing Accounting Information Systems, 10/e Romney/Steinbart1 of 95 C HAPTER 4 Relational Databases.
Databases and DBMSs Todd S. Bacastow January
- The most common types of data models.
Fundamentals of DBMS Notes-1.
Database Development Lifecycle
Introduction To DBMS.
CIS 336 AID Your Dreams Our Mission/cis336aid.com
HAPTER 4 Relational Databases.
Relational Databases Chapter 4.
Introduction To Database IT-402
Chapter 6 - Database Implementation and Use
Databases Chapter 16.
Information Systems Today: Managing in the Digital World
Introduction To Database Systems
Chapter 4 Relational Databases
Database Systems Instructor Name: Lecture-12.
Databases and Information Management
Introduction to Database Management System
Chapter 2 Database Environment Pearson Education © 2009.
Basic Concepts in Data Management
Chapter 2 Database Environment.
Data Base System Lecture : Database Environment
Accounting System Design
Database Fundamentals
Relational Database Model
MIS2502: Data Analytics Relational Data Modeling
Data Model.
Accounting System Design
Databases and Information Management
Flat Files & Relational Databases
Accounting Information Systems 9th Edition
logical design for relational database
Chapter 17 Designing Databases
Chapter 2 Database Environment Pearson Education © 2009.
Chapter 2 Database Environment Pearson Education © 2009.
Presentation transcript:

Relational Databases Chapter 4

Learning Objectives Explain the importance and advantages of databases, as well as the difference between database 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.

What Is a Database? Efficiently and centrally coordinates information for a related group of files

Let’s examine some basic principles about how data are stored in computer systems. An entity is anything about which the organization wishes to store data. At your college or university, one entity would be the student. STUDENT Student ID Student Last Name Student First Name Student Phone Number Student Birth Date 333-33-3333 Simpson Alice 333-3333 10/11/84 111-11-1111 Sanders Ned 444-4444 11/24/86 123-45-6789 Moore Artie 555-5555 04/20/85

A field is the physical space where an attribute is stored. Information about the attributes of an entity (e.g., the student’s ID number and birth date) are stored in fields. A field is the physical space where an attribute is stored. STUDENT Student ID Student Last Name Student First Name Student Phone Number Student Birth Date 333-33-3333 Simpson Alice 333-3333 10/11/84 111-11-1111 Sanders Ned 444-4444 11/24/86 123-45-6789 Moore Artie 555-5555 04/20/85

The example below shows the record for Artie Moore. All the fields containing data about one entity (e.g., one student) form a record. A record is the set of attributes stored for a particular instance of an entity. The example below shows the record for Artie Moore. STUDENT Student ID Student Last Name Student First Name Student Phone Number Student Birth Date 333-33-3333 Simpson Alice 333-3333 10/11/84 111-11-1111 Sanders Ned 444-4444 11/24/86 123-45-6789 Moore Artie 555-5555 04/20/85

A data value is the intersection of the row and column. The data value for Ned Sanders’ birth date is 11/24/86. STUDENT Student ID Student Last Name Student First Name Student Phone Number Student Birth Date 333-33-3333 Simpson Alice 333-3333 10/11/84 111-11-1111 Sanders Ned 444-4444 11/24/86 123-45-6789 Moore Artie 555-5555 04/20/85

A set of all related records forms a file (e.g., the student file). If this university only had three students and five fields for each student, then the entire file would be depicted below. STUDENT Student ID Student Last Name Student First Name Student Phone Number Student Birth Date 333-33-3333 Simpson Alice 333-3333 10/11/84 111-11-1111 Sanders Ned 444-4444 11/24/86 123-45-6789 Moore Artie 555-5555 04/20/85

Student File Class File Advisor File A set of interrelated, centrally coordinated files forms a database. When files about students are integrated with files about classes and files about advisors, we have a database. Student File Class File Advisor File

Database systems were developed to address the problems associated with the proliferation of master files. For years, each time a new information need arose, companies created new files and programs. The result: a significant increase in the number of master files.

This proliferation of master files created problems: Fact A Fact B Fact C This proliferation of master files created problems: Often the same information was stored in multiple master files. Made it more difficult to effectively integrate data and obtain an organization-wide view of the data. Also, the same information may not have been consistent between files. If a student changed his phone number, it may have been updated in one master file but not another. Enrollment Program Master File 2 Fact A Fact D Fact F Fin. Aid Program Master File 3 Fact A Fact B Fact F Grades Program

Database Fact A Fact B Fact C Fact D Fact E Fact F The combination of the database, the DBMS, and the application programs that access the database is referred to as the database system. Database Management System Enrollment Program Fin. Aid Program Grades Program

Advantages of Databases Data is integrated and easy to share Minimize data redundancy and data inconsistency Data is independent of the programs that use the data Data is easily accessed for reporting and cross- functional analysis

Database Users and Designers At one level of the database is the physical view of the data which is how the data is actually physically stored in the system. Designers of a database also need to understand user’s needs and the logical view of the entire database as well as the physical view.

DBMS Database Logical View—User A Logical View—User B Enrollment by Class DBMS The DBMS translates users’ logical views into instructions as to which data should be retrieved from the database. Operating System Database

Schemas Describe the logical structure of a database Conceptual Level External Level Internal Level

Schemas – Conceptual Level Conceptual Level Schema Organization wide view of the entire database Lists all data elements and the relationships among them

Schemas – external level External Level Schema Individual users view of portions of a database Each view is a subschema

Schemas – Internal Level Internal Level Schema Low-level view of the database Describes how data are stored and accessed Description of: records, definitions, addresses, and indexes

Mapping external-level views to conceptual level schema Mapping conceptual-level items to internal-level descriptions

Database Design To design a database, you need to have a conceptual view of the entire database. The conceptual view illustrates the different files and relationships between the files. The data dictionary is a “blueprint” of the structure of the database and includes data attributes, field types, programs that use the data element, outputs, and so on.

DBMS Languages Data Definition Language (DDL) Data Manipulation Language (DML) Data Query Language (DQL)

Data definition language (ddl) Builds the data dictionary Creates the database Describes logical views for each user Specifies record or field security constraints - Example of DDL Language to create a table: create table emp (empno number(5) primary key,                    name varchar2(20),                    sal number(10,2),                    job varchar2(20),                    mgr  number(5),                    Hiredate  date,                    comm number(10,2));

Data manipulation language (dml) Changes the content in the database Creates, updates, insertions, and deletions

Data query language (dql) Enables users to retrieve, sort, and display specific data from the database Example (list all employees from Indianapolis by employee ID): SELECT EMP_ID, LAST_NAME FROM EMPLOYEE_TBL WHERE CITY = 'INDIANAPOLIS‘ ORDER BY EMP_ID;

RELATIONAL DATABASES A DBMS is characterized by the type of logical data model on which it is based. A data model is an abstract representation of the contents of a database. Most new DBMSs are called relational databases because they use the relational model developed by E.F. Codd in 1970. The relational data model represents everything in the database as being stored in the forms of tables (aka, relations).

A primary key is the attribute or combination of attributes that uniquely identifies a specific row in a table.

STUDENT Student ID Last Name First Name Phone No. Advisor No. 333-33-3333 Simpson Alice 333-3333 1418 111-11-1111 Sanders Ned 444-4444 123-45-6789 Moore Artie 555-5555 1503 ADVISOR Advisor No. Last Name First Name Office No. 1418 Howard Glen 420 1419 Melton Amy 316 1503 Zhang Xi 202 1506 Radowski J.D. 203 A foreign key is an attribute in one table that is a primary key in another table. Used to link the two tables.

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.

RELATIONAL DATABASES Alternatives for Storing Data One possible alternate approach would be to store all data in one uniform table. For example, instead of separate tables for students and classes, we could store all data in one table and have a separate line for each student - class combination.

In the above, simplified example, a number of problems arise. Student ID Last Name First Name Phone No. Course CRN Course No Day Time 333-33-3333 Simpson Alice 333-3333 90111 ACCT-3603 M 9:00 AM 90222 FIN-3213 Th 11:00 AM 90333 MGMT-3021 TH 12:00 PM 111-11-1111 Sanders Ned 444-4444 90444 ACCT-3433 T 10:00 AM 90334 W 8:00 AM 90555 ANSI-1422 F 123-45-6789 Moore Artie 555-5555 Using the suggested approach, a student taking three classes would need three rows in the table. In the above, simplified example, a number of problems arise.

This problem is referred to as an update anomaly. Student ID Last Name First Name Phone No. Course CRN Course No Day Time 333-33-3333 Simpson Alice 333-3333 90111 ACCT-3603 M 9:00 AM 90222 FIN-3213 Th 11:00 AM 90333 MGMT-3021 TH 12:00 PM 111-11-1111 Sanders Ned 444-4444 90444 ACCT-3433 T 10:00 AM 90334 W 8:00 AM 90555 ANSI-1422 F 123-45-6789 Moore Artie 555-5555 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.

This problem is referred to as an insert anomaly. Student ID Last Name First Name Phone No. Course CRN Course No Day Time 333-33-3333 Simpson Alice 333-3333 90111 ACCT-3603 M 9:00 AM 90222 FIN-3213 Th 11:00 AM 90333 MGMT-3021 12:00 PM 111-11-1111 Sanders Ned 444-4444 90444 ACCT-3433 T 10:00 AM 90334 W 8:00 AM 90555 ANSI-1422 F 123-45-6789 Moore Artie 555-5555 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.

This problem is referred to as a delete anomaly. Student ID Last Name First Name Phone No. Course CRN Course No Day Time 333-33-3333 Simpson Alice 333-3333 90111 ACCT-3603 M 9:00 AM 90222 FIN-3213 Th 11:00 AM 90333 MGMT-3021 12:00 PM 111-11-1111 Sanders Ned 444-4444 90444 ACCT-3433 T 10:00 AM 90334 W 8:00 AM 90555 ANSI-1422 F 123-45-6789 Moore Artie 555-5555 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.

The solution to the preceding problems is to use a set of tables in a relational database. Each entity is stored in a separate table, and separate tables or foreign keys can be used to link the entities together.

Primary Key is the combination of StudentID and CourseCRN For Examples, Row 1 PK = 333-33-333-1234 This allows it to be a unique ID

Add a student here. Leaves no blank spaces. Add a course here. Leaves no blank spaces. When a particular student enrolls for a particular course, add that info here.

Ned still exists in the student table. Even if Ned was the only student in the class, ACCT-3603 still exists in the course table. If Ned Sanders drops ACCT-3603, remove Ned’s class from this table.

Relational Database Design Rules There are 4 key rules to follow when it comes to relational databases Following these rules allows databases to be normalized and solves the update, insert, and delete anomalies.

Relational Database Design Rules Every column in a row must be single valued There can only be one value per field i.e. Even though each sale can involve more than one item, you have to use one row for each unique item sold Invoice # Date Item # Quantity Price per 102 1/5/17 1007,1889,5572 2,12,3 $15.31,$12.15, $38.17 Right Invoice # Date Item # Quantity Price per 102 1/5/17 1007 2 $15.31 1889 12 $12.15 5572 3 $38.17

Relational Database Design Rules Primary key cannot be null (empty) Known as entity integrity A Primary Key cannot uniquely identify a row in a table if it is null (empty) A NONnull primary key ensures that every row in a table represents something and can be identified SSN Last Name First Name City Country 555-55-8992 Lannister Cersei Kings Landing Westeros Jaime 555-55-9991 Baratheon Joffrey

Relational Database Design Rules IF a foreign key is not null, it must have a value that corresponds to the value of a primary key in another table Known as referential integrity Foreign keys link rows in one table to rows in another table Ensures database consistency Foreign keys can contain null values for example when customers pay cash

Relational Database Design Rules All nonkey attributes in the table must describe characteristics of the object identified by the primary key Most tables contain other attributes in addition to the primary and foreign keys i.e. details about a person should not include descriptions of snow SSN Last Name First Name Color of Snow City Country 555-55-8992 Lannister Cersei White Kings Landing Westeros 555-55-8993 Jaime 555-55-9991 Baratheon Joffrey

RELATIONAL DATABASES There are two basic ways to design well- structured relational databases. Normalization Semantic data modeling

RELATIONAL DATABASES Normalization Starts with the assumption that everything is initially stored in one large table. A set of rules is followed to decompose that initial table into a set of normalized tables. Objective is to produce a set of tables in third- normal form (3NF) because such tables are free of update, insert, and delete anomalies. Approach is beyond the scope of this book but can be found in any database textbook.

RELATIONAL DATABASES Semantic data modeling (covered in detail in Chapters 17 and 18) Database designer uses knowledge about how business processes typically work and the information needs associated with transaction processing to draw a graphical picture (ERD) of what should be included in the database. The resulting graphic is used to create a set of relational tables that are in 3NF.

RELATIONAL DATABASES Advantages over simply following normalization rules: Semantic data modeling uses the designer’s knowledge about business processes and practices; it therefore facilitates efficient design of transaction processing databases. The resulting graphical model explicitly represents information about the organization’s business processes and policies and facilitates communication with intended users.

As accountants, you are likely to audit or work for companies that use database technology to store, process, and report accounting transactions. Many accountants work directly with databases and will enter, process, and query databases. Some will develop and evaluate internal controls necessary to ensure database integrity. Others will be involved in the design and management of databases.