Chapter 4 Relational Databases 4-1 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. 4-2 Database A set of interrelated, centrally coordinated data files that are stored with as little data redundancy as possible. A database consolidates records previously stored in separate files into a common pool and serves a variety of users and data processing applications. 4-4 Field Attributes about an entity Data Hierarc hy. Record Related group of fields File Related group of records Database Related group of files 4-5 4-6 File-Oriented Systems versus Database Systems 4-7 Using Data Warehouses for Business Intelligence A data warehouse is one or more very large databases containing both detailed and summarized data for a number of years that is used for analysis rather than transaction processing OLAP DATA MINING Business Intelligence ===> using Data Warehouse for strategic decision making 4-8 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 4-9 Advantages of Database Systems Data Integration Data Sharing Minimizing Data Redundancy and Data Inconsistency Data Independence Cross-Functional Analysis 4-10 Logical vs. Physical View of Data Physical View • The way data are physically arranged and stored in the computer system. • Depends on explicitly knowing: • How is the data actually arranged in a file • Where is the data stored on the computer 4-11 Logical View • How people conceptually organize, view, and understand the relationships among data items. • Unnecessary to explicitly know how and where data is stored. • For example, a sales manager views all customer information as being stored in a table. 4-12 A schema is a description of the data elements in a database, the relationships among them, and the logical model used to organize and describe the data. The the organization-wide view of the entire conceptual-level database, lists all data elements and the relationships among them. schema The external-level schema an individual user’s view of portions of a database The internal-level schema a low-level view of the database, describes how the data are stored and accessed, including record layouts, definitions, addresses, and indexes. 4-13 4-15 Data Dictionary data dictionary contains information about the structure of the database. 4-16 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 Data Query Language (DQL) Enables the retrieval, sorting, and display of data from the database 4-17 Relational Database Relational data model representsconceptual- and external-level schemas as if data are stored in two-dimensional tables Table • Each row called a tuple, contains data about a specific item in a database table. This is equivalent to a record • Each column contains data about an attribute of of an entity. This is equivalent to a field 4-18 4-19 Row (Record) A Relational Table Each row contains multiple attributes describing an instance of the entity. In this case, inventory. Column (Field) 4-20 Type of Attributes – Relational Database System Primary Key the database attribute, or combination of attributes, that uniquely identifies a specific row in a table. Foreign Key an attribute in a table that is also a primary key in another table and is used to link the two tables. 4-21 4-22 Database Design Errors Update Anomaly Changes to existing data are not correctly recorded. Due to multiple records with the same data attributes Insert Anomaly there is no way to store information about prospective customers until they make a purchase. Unable to add a record to the database. Delete Anomaly occurs when deleting a row has unintended consequences. removing a record also removes unintended data from 4-23 the database. Design Requirements for Relational Database Every column in a row must be single valued. Primary keys cannot be null Foreign keys, if not null, must have values that correspond to the value of a primary key in another table. All nonkey attributes in a table must describe a characteristic of the object identified by the primary key 4-24 Two Approaches to Database Design Normalization • Following relational database creation rules to design a relational database that is free from delete, insert, and update anomalies. • Decomposed set of tables are in third normal form (3NF). semantic data modeling • Using knowledge of business processes and information needs to create a diagram that shows what to include in a fully normalized database (in 3NF). 4-25 SELESAI