0% found this document useful (0 votes)
2 views61 pages

Week 2

This document covers the fundamentals of relational database design and SQL, focusing on data modeling, the importance of data models, and various types of data models including hierarchical, network, and relational models. It discusses key concepts such as entities, attributes, relationships, and business rules, as well as integrity rules and relational algebra for manipulating data. The document also outlines the levels of data abstraction and the characteristics of relational tables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views61 pages

Week 2

This document covers the fundamentals of relational database design and SQL, focusing on data modeling, the importance of data models, and various types of data models including hierarchical, network, and relational models. It discusses key concepts such as entities, attributes, relationships, and business rules, as well as integrity rules and relational algebra for manipulating data. The document also outlines the levels of data abstraction and the characteristics of relational tables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 61

COMP 1630

Relational Database Design and SQL

Week 2
Chapter 2

Database Models
Learning Objectives
After completing this chapter, you will be able to:
 Discuss data modeling and why data models are important
 Describe the basic data-modeling building blocks
 Define what business rules are and how they influence database design
 Understand how the major data models evolved
 List emerging alternative data models and the needs they fulfill
 Explain how data models can be classified by their level of abstraction
Data Modeling & Data Models

■ Data modeling: creating a specific data model for a determined


problem domain
– Data model: simple representation of complex real-world data
structures
■ Useful for supporting a specific problem domain
– Model: abstraction of a more complex real-world object or event
The Importance of Data Models
The importance of data modeling cannot be overstated
– Facilitates communication
– Gives various views of the database
– Organizes data for various users
– Provides an abstraction for the creation of good a database
Data Model Basic Building Blocks

Entity: person, place, thing, or event about which data will be collected
and stored
– Attribute: characteristic of an entity
– Relationship: association among entities
■ One-to-many (1:M OR 1..*)
■ Many-to-many (M:N or *..*)
■ One-to-one (1:1 OR 1..1)
– Constraint: restriction placed on data
■ Ensures data integrity
Business Rules

Brief, precise, and unambiguous description of a policy, procedure, or


principle
– Create and enforce actions within that organization’s environment
– Establish entities, relationships, and constraints
Discovering Business Rules
Sources of business rules

Company
managers
Reasons for identifying and
Policy makers documenting business rules
Department
managers Assist designers
• Understand the nature, role,
Facilitate
scope of data, and business
Standardize company’s communications tool
Written processes
view of data between users and • Develop appropriate
documentation
designers relationship participation rules
and constraints
Direct • Create an accurate data model
interviews with
end users
Translating Business Rules into
Data Model Components

Business rules set the stage for Relationships are


the proper identification of bidirectional
entities, attributes,
relationships, and constraints
Nouns translate into entities Questions to identify the relationship type
Verbs translate into relationships among • How many instances of B are related to one
entities instance of A?
• How many instances of A are related to one
instance of B?
Entity name requirements

• Be descriptive of the objects in the business


environment
• Use terminology that is familiar to the users

Naming Attribute name


Conventio • Required to be descriptive of the data

ns represented by the attribute

Proper naming

• Facilitates communication between parties


• Promotes self-documentation
Hierarchical and Network Models
• Developed to manage large amounts of data for complex
manufacturing projects
Hierarchical • Represented by an upside-down tree which contains segments
models  Segments are the equivalent of a file system’s record type
• Depicts a set of one-to-many (1:M) relationships

• Created to represent complex data relationships effectively


Network models • Improved database performance and imposed a database standard
• Allows a record to have more than one parent

• Emerged with the network model are still used by modern data
models
Standard database • Schema and subschema
concepts • Data manipulation language (DML)
• Data definition language (DDL)
The Relational Model (1 of 3)

• Describes a precise set of data manipulation constructs

Model
• Performs basic functions provided by the
Relational hierarchical and network DBMS systems
• Makes the relational data model easier to
database understand and implement
management • Hides the complexities of the relational
model from the user
system (RDBMS)
Produced an automatic • Based on a relation (i.e., table):
matrix composed of intersecting
transmission database tuples (rows) and attributes
that replaced standard (columns)

transmission databases
The Relational Model (2 of 3)
The Relational Model (3 of 3)
SQL-based relational database application:

End-user interface
• Allows end user to interact with the data

Collection of tables stored in the database


• Each table is independent from another
• Rows in different tables are related based on common values in
common attributes

SQL engine
• Executes all queries
The Entity Relationship Model
Graphical representation of entities and their relationships in a database
structure

Entity relationship Entity instance or entity


diagram (ERD) occurrence
• uses graphic representations
to model database
components • rows in the relational table

Attributes Connectivity

• describe particular • term used to label the relationship


characteristics types
The Object-Oriented Data Model
■ Both data and its relationships are contained in a single structure known
as an object
– Object-oriented database management system(OODBMS): based on
Unified
OODM Class Modeling
Object Attribute Class Inheritance
hierarchy Language
(UML)
• contains data • describes the • collection of • resembles an • object • describes
and their properties of similar upside-down inherits sets of
relationships an object objects with tree in which methods and diagrams and
with shared each class attributes of symbols to
operations structure and has only one classes above graphically
that are behavior parent it model a
performed on organized in system
it a class
• Basic hierarchy
building
block for
autonomous
structures
• Abstraction
of real-world
entity
Object/Relational and XML

■ Extended relational data model (ERDM)


– Supports OO features, extensible data types based on classes,
and inheritance
■ Object/relational database management system (O/R DBMS): based
on ERDM
■ Extensible Markup Language (XML)
– Manages unstructured data for efficient and effective exchange of
structured, semistructured, and unstructured data
Emerging Data Models: Big Data
Find new and
better ways to
Provide high
manage large
Goals amounts of web
performance at a
reasonable cost
and sensor-
generated data

Characteristi Volume Velocity Variety


cs

OLAP tools
Volume doesn’t proved
allow usage of inconsistent
Challenges conventional
Expensive
dealing with
structures unstructured
data

New Hadoop
Hadoop
Distributed File MapReduce NoSQL
technologies System (HDFS)
Emerging Data Models: NoSQL

■ NoSQL databases
– Not based on the relational model
– Support distributed database architectures
– Provide high scalability, high availability, and fault tolerance
– Support large amounts of sparse data
– Geared toward performance rather than transaction consistency
– Provides a broad umbrella for data storage and manipulation
Discussion: ■ Hierarchical Model
■ Network Model

Advantages ■ Relational Model


■ Entity Relationship Model
& ■ Object-Oriented Model

Disadvantag ■ NoSQL

es
End users’
People who use the
view of the application programs to
manipulate the data and
data
environment
generate information
The
ER
External
diagrams
are used to
External schema:
specific
Model
representation of an
represent external view
the external
views
The Conceptual Model

■ Represents a global view of the entire database by the entire


organization
– Conceptual schema: basis for the identification and high-
level description of the main data objects
– Logical design: task of creating a conceptual data model
■ Conceptual model advantages
– Macro-level view of data environment
– Software and hardware independent
The Internal Model

■ Representing database as seen by the DBMS mapping


conceptual model to the DBMS
– Internal schema: specific representation of an internal
model, using the database constructs supported by the
chosen database
– Logical independence: changing internal model without
affecting the conceptual model
– Hardware independent: unaffected by the type of
computer on which the software is installed
The Conceptual Model (2 of 2)
The Physical Model

■ Operates at lowest level of abstraction


– Describes the way data are saved on storage media such as
magnetic, solid state, or optical media
■ Requires the definition of physical storage and data access
methods
– Software and hardware dependent
■ Relational model aimed at logical level
– Does not require physical-level details
■ Physical independence: changes in physical model do not affect
internal model
Levels of Data Abstraction

Model Degree of Focus Independent of


Abstraction
External High End-user views Hardware and software

Conceptu Medium-High Global view of data Hardware and software


al (database model
independent)
Internal Medium-Low Specific database model Hardware

Physical Low Storage and access methods Neither hardware nor software
Summary

■ A data model is an abstraction of a complex real-world data


environment
■ There are many types of data models (e.g., hierarchical, network,
relational, object-oriented, extended relational data model, etc.)
■ Data-modeling requirements are a function of different data views
(global versus local) and the level of data abstraction
Chapter 3
The Relational Database
Model
Learning Objectives
After completing this chapter, you will be able to:
■ Describe the relational database model’s logical structure
■ Identify the relational model’s basic components and explain the structure,
contents, and characteristics of a relational table
■ Use relational database operators to manipulate relational table contents
■ Explain the purpose and components of the data dictionary and system
catalog
■ Identify appropriate entities and then the relationships among the entities in
the relational database model
■ Describe how data redundancy is handled in the relational database model
■ Explain the purpose of indexing in a relational database
A Logical View of Data
■ Relational database model enables logical representation of the data and its
relationships
– Logical simplicity yields simple and effective database design methodologies
– The logical view is facilitated by the creation of data relationships based on a
logical construct called a relation
Tables and Their Characteristics

Table 3.1 Characteristics of a Relational Table

1 A table is perceived as a two-dimensional structure composed of rows and


columns.
2 Each table row (tuple) represents a single entity occurrence within the entity
set.
3 Each table column represents an attribute, and each column has a distinct
name.
4 Each intersection of a row and column represents a single data value.
5 All values in a column must conform to the same data format.
6 Each column has a specific range of values known as the attribute domain.
7 The order of the rows and columns is immaterial to the DBMS.
8 Each table must have an attribute or combination of attributes that uniquely
identifies each row.
Keys

■ Keys consist of one or more attributes that determine other attributes


– Ensure that each row in a table is uniquely identifiable
– Establish relationships among tables and to ensure the integrity
of the data
■ Primary key: attribute or combination of attributes that uniquely
identifies a row
Dependencies

■ Determination
– State in which knowing the value of one attribute makes it possible
to determine the value of another
■ Establishes the role of a key
■ Based on the relationships among the attributes
■ Functional dependence: value of one or more attributes determines the
value of one or more other attributes
– Determinant: attribute whose value determines another
– Dependent: attribute whose value is determined by the other
attribute
■ Full functional dependence: entire collection of attributes in the
determinant is necessary for the relationship
Types of Keys (1 of 3)

Several different types of keys are used in the relational model


■ Composite key: key that is composed of more than one attribute
■ Key attribute: attribute that is a part of a key
■ Superkey: key that can uniquely identify any row in the table
■ Candidate key: minimal superkey
■ Entity integrity: condition in which each row in the table has its own unique identity
– All of the values in the primary key must be unique
– No key attribute in the primary key can contain a null
■ Null: absence of any data value
– Unknown attribute value, known but missing attribute value, or inapplicable
condition
■ Referential integrity: every reference to an entity instance by another entity instance is
valid
■ Foreign key: primary key of one table that has been placed into another table to create a
common attribute
■ Secondary key: key used strictly for data retrieval purposes
Types of Keys (2 of 3)
Types of Keys (3 of 3)

Key Type Definition


Superkey An attribute or combination of attributes that uniquely identifies each
row in a table.
Candidate A minimal (irreducible) superkey;
key a superkey that does not contain a subset of attributes that is itself a
superkey.
Primary key A candidate key selected to uniquely identify all other attribute values in
any given row; cannot contain null entries.
Foreign key An attribute or combination of attributes in one table whose values must
either match the primary key in another table or be null.
Secondary An attribute or combination of attributes used strictly for data retrieval
key purposes.
Integrity Rules (1 of 2)

■ Relational database integrity rules are very important to good database design
– Relational database management systems (RDBMSs) enforce integrity rules
automatically
■ Much safer to make sure the application design conforms to entity and
referential integrity rules

■ Ways to handle nulls


– Flags
■ Special codes used to indicate the absence of some value
– Constraints
■ NOT NULL constraint: placed on a column to ensure that every row in the table
has a value for that column
■ UNIQUE constraint: restriction placed on a column to ensure that no duplicate
values exist for that column
Integrity Rules (2 of 2)

Entity Integrity

• Requirement
• All primary key entries are unique, and no part of a primary key may be null.
• Purpose
• Each row will have a unique identity, and foreign key values can properly reference primary key
values.
• Example
• No invoice can have a duplicate number, nor can it be null; in short, all invoices are uniquely
identified by their invoice#.
Referential Integrity

• Requirement
• A foreign key may have either a null entry, as long as it is not a part of its table’s primary key, or
an entry that matches the primary key value in a table to which it is related (every non-null
foreign key value must reference an existing primary key value).
• Purpose
• It is possible for an attribute not to have a corresponding value, but it will be impossible to have
an invalid entry; the enforcement of the referential integrity rule makes it impossible to delete a
row in one table whose primary key has mandatory matching foreign key values in another table.
• Example
• A customer might not yet have an assigned sales representative (number), but it will be
impossible to have an invalid sales representative (number).
Relational Algebra
■ Theoretical way of manipulating table contents using relational operators
– Relvar: variable that holds a relation
■ Heading contains the names of the attributes
■ Body contains the relation
– Relational operators have the property of closure
■ Closure: use of relational algebra operators on existing relations produces new relations
Relational Set Operators (1 of
10)
■ Select (restrict)
– Unary operator that yields a horizontal subset of a table
■ Project
– Unary operator that yields a vertical subset of a table
■ Union
– Combines all rows from two tables, excluding duplicate rows
– Union-compatible: tables share the same number of columns, and their
corresponding columns share compatible domains
■ Intersect
– Yields only the rows that appear in both tables
– Tables must be union-compatible to yield valid results
Relational Set Operators (2 of
10)
Relational Set Operators (3 of
10)
Relational Set Operators (4 of
10)
Relational Set Operators (5 of
10)
■ Difference
– Yields all rows in one table that are not found in the other table
– Tables must be union-compatible to yield valid results
Relational Set Operators (6 of
10)
■ Product: Yields all possible pairs of rows from two tables
Relational Set Operators (7 of 10)

■ Joins allow information to be intelligently combined from two or more tables


– Natural join: links tables by selecting only the rows with common values in their
common attribute
– Equijoin: links tables on the basis of an equality condition that compares specified
columns of each table
– Theta join: links tables using an inequality comparison operator
– Inner join: only returns matched records from the tables that are being joined
– Outer join: matched pairs are retained and unmatched values in the other table are left
null
■ Left outer join: yields all of the rows in the first table, including those that do not have a
matching value in the second table
■ Right outer join: yields all of the rows in the second table, including those that do not have
matching values in the first table
Relational Set Operators (8 of
10)
Relational Set Operators (9 of 10)

■ Divide
– Uses one double-column table as the dividend and one single-column table
as the divisor
– Output is a single column that contains all values from the second column
of the dividend that are associated with every row in the divisor
Relational Set Operators (10 of
10)
Data Dictionary and the System
Catalog
■ Data dictionary
– Description of all tables in the database created by the user and
designer
■ System catalog
– System data dictionary that describes all objects within the database
■ Homonyms and synonyms must be avoided to lessen confusion
– Homonym: same name is used to label different attributes
– Synonym: different names are used to describe the same attribute
Relationships within the Relational Database

■ One-to-many (1:M)
– Norm for relational databases
■ One-to-one (1:1)
– One entity can be related to only one other entity and vice versa
■ Many-to-many (M:N)
– Implemented by creating a new entity in 1:M relationships with the
original entities
– Composite entity (i.e., bridge or associative entity): helps avoid
problems inherent to M:N relationships
■ Includes the primary keys of tables to be linked
Data Redundancy (Revisited)
■ The relational database facilitates control of data redundancies through use of
foreign keys
– Common attributes that are shared by tables
■ To be controlled except the following circumstances:
– Sometimes data redundancy must be increased to make the database serve
crucial information purposes
– Sometimes data redundancy exists to preserve the historical accuracy of data
Indexes

■ Orderly arrangement to logically access rows in a table


– Index key: index’s reference point that leads to data location identified
by the key
– Unique index: index key can have only one pointer value associated
with it
■ Each index is associated with only one table
– The index key can have multiple attributes
Summary

■ Tables are the basic building blocks of a relational database


– Keys are central to the use of relational tables
■ Each table row must have a primary key
– Although tables are independent, they can be linked by
common attributes
■ The relational model supports several relational algebra
functions
– A relational database performs much of the data
manipulation work behind the scenes
– Once you know the basics of relational databases, you
can concentrate on design

You might also like