Professional Documents
Culture Documents
Database Design and Creation
Database Design and Creation
Customers
Jobs
Skills
Employees
Generating Information for Decision Making
Types of Database Systems
Number of Users Location
Single-user Centralized
Multiuser Distributed
Scope Use
Desktop Transactional
Workgroup (Production)
Enterprise Analytical
Types of Databases
Central
Computer
Client Server Databases
Client
Client
Network
Database
Server
Client
Distributed Databases
Location B
Location C
computer
computer
Homogeneous
computer Databases
Location A
Distributed Databases
Heterogeneous Client
Or Federated Remote
Databases Comp.
Database
Server
Local Network
Comm
Server
Remote
Client Comp.
Evolution of Database
Technologies
Hierarchical Model
The simplest database model arranges record types
as hierarchy
In a hierarchical database, a record type is
referred to as a node or “segment.”
The top node of the hierarchy is referred to as the
root node
A parent node can have more than one child node
A child node can have only one parent node
Hierarchical Model
Network Model
The network database model allows many-to-many
relationships in addition to one-to-many
relationships
Related record types are referred to as a network
set, or simply a “set.”
A set contains an owner and members
An owner is similar to a parent record in a
hierarchical database
A member is roughly equivalent to the child records
in a hierarchical database
Network Model
Relational Database Model
It produces databases that are difficult to
create, manipulate, and maintain
A relational database stores data in a
collection of related tables
Each table (also called a “relation”) is a
sequence, or list, of records.
All of the records in a table are of the
same record type
Relational Database
Relational Database
Object Oriented Database
An object-oriented database stores data as
objects, which can be grouped into object classes,
and defined by attributes and method
A class specifies the attributes and methods that are
shared by all objects in a class
A class attribute is equivalent to a field, and contains
the smallest unit of data.
A method is any behavior that the object is capable
of performing
Object Oriented Database
Types of Database Models
Oracle
IBM
Microsoft
Informix
Sybase
Table
is the chief structure in a relational database. It is
composed of fields and records, the order of
which is completely unimportant.
Field
Field - (known as an attribute in relational
database theory) is the smallest structure in a
relational database.
Record
(known as a tuple in relational database
theory) is a structure within a table that
represents a unique instance of the
subject of the table.
View
A virtual table that is
composed of the fields of
one or more data or
validation tables. A View
is considered "virtual"
because it doesn't store
any data on its own;
instead it draws its data
from the tables on which
it is based.
Keys
A special fields that serve specific
purposes within a table, and the type of
key determines its use within the table.
Primary key is a field that uniquely identifies
a record within a table.
Foreign key, which is a field that is used to
establish a relationship between a pair of
tables.
Keys
Index
A structure within an RDBMS that is used
to improve data processing
Keys are logical structures used to identify
records within a table, and indexes are
physical structures used to optimize data
processing.
Relationships
A connection
established between
a pair of tables
Types of Relationships
one-to-one - exists
between a pair of tables if
a single record in the first
table is related to only
one record in the second
table, and a single record
in the second table is
related to only one record
in the first table
Types of Relationships
one-to-many - exists
between a pair of tables if
a single record in the first
table can be related to
one or more records in
the second table, but a
single record in the
second table can be
related to only one record
in the first table
Types of Relationships
many-to-many - exists
between a pair of tables if
a single record in the first
table can be related to
one or more records in
the second table, and a
single record in the
second table can be
related to one or more
records in the first table.
Types of Participation
Mandatory – if
relationship must
exist
Optional – if
relationship is
optional
Degree of Participation
Degree of Participation
the minimum and maximum number of
records in one table that can be related to a
single record in the other table.
Data Integrity
refersto the validity, consistency, and
accuracy of the data in a database.
Types of Integrity
Table-level integrity ensures that the field that identifies each record
within the table, is unique and is never missing its value.
Field-level integrity ensures that the structure of every field is sound,
that the values in each field are valid, consistent, and accurate, and
that fields of the same type (such as City fields) are consistently
defined throughout the database.
Relationship-level integrity (traditionally known as referential
integrity) ensures that the relationship between a pair of tables is
sound and that there is synchronization between the two tables
whenever data is entered, updated, or deleted.
Business rules impose restrictions or limitations on certain aspects
of a database based on the ways an organization perceives and
uses its data.
Schema
The term schema or database schema
simply means the structure or design of
the database—that is, the form of the
database without any data in it. If you like,
the schema is a blueprint for the data in
the database.
employee(employeeID, name, job, departmentID)
Database
Development and
Design
The Information System
Provides for data collection, storage, and retrieval.
Consists of
People
Hardware
Software
Database(s)
Application programs
Procedures
Also facilitates the transformation of data into information
and the management of both data and information.
The Systems Development Life
Cycle (SDLC)
Five phases of SDLC:
Planning
Analysis
DetailedSystems Design
Implementation
Maintenance
Database Development
process of database design and implementation
takes place within the confines of an IS
Attributes
Relationship types
Attributes on relationships
Tiny College Entities
Weak versus Strong Entities
Weak Entity Type Strong Entity Type
Cannot exist in the Is not existence-
database unless dependent on some
another type of entity other entity type
also exists in the
database
Identifying owner
Identifying
relationship
A Weak Entity in an ERD
Attributes
Properties that describe the entity’s
characteristics
Represented by ovals and are connected
to the entity with a line.
Have a domain -- the attribute’s set of
possible values.
Attributes may share a domain.
Primary keys are underlined.
Keys
Candidate key
An attribute or set of attributes that uniquely
identifies individual occurrences of an entity
type.
Primary key
The candidate key selected to be the primary
key.
Composite key
A candidate key that consists of two or more
attributes.
The Attributes of the STUDENT
Entity
Basic E-R Model Entity Presentation
Problems with Multivalued
Attributes
The relational DBMS cannot implement
multivalued attributes.
Solutions:
Within the original entity, create several
new attributes, one for each of the original
multivalued attribute’s components
Create a new entity composed of the
original multivalued attribute’s components
Splitting the Multivalued Attributes into New
Attributes
A New Entity Set Composed of Multivalued
Attribute’s Components
Derived Attributes
A derived attribute is not physically stored within
the database; instead, it is derived by using an
algorithm.
Relationships
an association between entities
Degree of the Relationship
Access rules
GRANT ALL PRIVILEGES
ON staff
TO admin;
Creating Database
Structured Query
Language
SQL Basics: How does a query
language like SQL work?
DESCRIBE sales_rep;
DESCRIBE student;
Dropping a Primary Key
ALTER TABLE tablename DROP Primary
Key
SELECT sid
FROM scores
WHERE points between 50 and 70;
Another Example
Which players are between 25 and 27
years old?
SELECT PLAYNUM, PLAYNAME
FROM PLAYERS
WHERE AGE BETWEEN 25 AND 27;
1779 Jones
2007 Dobbs
4280 Cohen
5410 Smith
Set Membership Search
Condition (IN/NOT IN)
SELECT contactid, name, age
FROM contact
WHERE age IN (15, 20, 25, 30);
Set Membership Search
Condition (IN/NOT IN)
Which teams are in New York or Detroit?
SELECT TEAMNUM
FROM TEAMS
WHERE TEAMCITY IN (‘New York’, ‘Detroit’);
Pattern Match Search Condition
(LIKE/NOT LIKE)
% represents any sequence of zero or more
characters (wildcard)
_ underscore represents any single character
Alternatively:
SELECT STUDENT.Name
FROM STUDENT INNER JOIN ENROLLMENT ON
STUDENT.SID = ENROLLMENT.StudentNumber
WHERE ENROLLMENT.ClassName=‘BD445’;
Using an ALIAS
SELECT s.studentid, s.lname, s.fname,
c.subjectid
FROM tblstudent as s, tblstudent_subject
as c
WHERE s.studentid=c.studentid;
Exercises
Create a query that will show:
All the teachers of a student
First name|Last name | Teacher
How many subjects that the teacher teaches
Teacher Name | CountSubjects
Student their subjects and their teachers
First Name|Last name | subject name | teacher
name
Joining together tables
People
SELECT name,phone,zip FROM Id Name Addressid
people, phonenumbers, address 1 Joe 1
WHERE
2 Jane 2
people.addressid=address.addressid
AND people.id=phonenumbers.id; 3 Chris 3
PhoneNumbers
PhoneID Id Phone
1 1 5532 Address
2 1 2234 AddressID Company Address Zip
1 ABC 123 12345
3 1 3211
2 XYZ 456 14454
4 2 3421
3 PDQ 789 14423
5 3 2341
6 3 3211
Different types of JOINs
“Inner Join”
Unmatched rows in either table aren’t printed
“Left Join”
All records from the “left” side are printed
“Right Join”
All records from the “right” side are printed
General form of SELECT/JOIN
SELECT columns,…
FROM left_table
join_type JOIN right_table ON condition
WHERE condition;
Using Join (INNER)
SELECT fname, course FROM tblStudents
INNER JOIN tblStudentCourse ON
studentid=studentid;
Will display students with courses.
Original Form:
SELECT fname, course FROM tblStudents
studentid=studentid;
Using Join (LEFT)
SELECT a.fname, a.course, b.subjectid
FROM tblStudent as a
LEFT JOIN tblStudent_Subject as b ON
a.studentid=b.studentid;
Will display students with courses. Null values
will be shown in the field where subject does
not exist
Using Join (RIGHT)
SELECT fname, course
FROM tblStudents as a
RIGHT JOIN tblStudent_Subject as b
ON a.studentid=b.studentid;
Will display course with students. Null values
will be shown in the student field in subjects
with no student.
Using SQL in
MySQL RDBMS
Using mysql in the command
prompt
Go to:
C:\apachefriends\xampp\mysql\bin
Using MySQL Command Line
Make sure you are in the /mysql/bin
directory.
Type mysql or mysql –u root or mysql – u
(username) – p (password)
Show Databases
To see what databases exist on this
server, type the following:
Use command
Show Tables Command
To list the columns of a selected table
Describe tablename
Shows the fields within a table
Create Database Command
Drop Database
Creating Tables
Inserting Data