0% found this document useful (0 votes)
19 views29 pages

CSE031.Lecture - 05.introduction To Database - Fall 2019

Uploaded by

Bishoy Emad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views29 pages

CSE031.Lecture - 05.introduction To Database - Fall 2019

Uploaded by

Bishoy Emad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Computer and Systems Engineering Department

Ain Shams University, Cairo, Egypt


Core concepts
• Data are valuable organizational resources
• Database is one of the technologies to manage and process Data
• Processing includes:
• Transactions: Passing data into and out of the database
• Presentation (appearance/format) columns, labels, grouping
• Transformation (data type, value conversions…): number to text or text to
number, value conversions such as degrees F to
• Aggregation: sum, count, average and other mathematical formulas that
evaluate across a group of records Example: average temperature
Definitions
• Data, Information and Knowledge:

• Data consists of numbers, text, graphics, images, sound and video segments
that have meaning to user’s environment.

• Information: Information is data + context that gives it meaning.

• Knowledge is used for making decisions. It is derived from information by


applying rules to it.
.
Core concepts and definitions (cont.)
Data Examples

• 0.14, 0.17, 0.20;


• 9:00, 160/95, 10:00, 155/92, 11:00, 130/90;
• AAB

4
Core concepts and definitions (cont.)
Data vs Information
Core concepts and definitions (cont.)
Data ->Information -> Knowledge
Background and History
• Manual filing systems.

• In a manual system, files are labeled


and stored in cabinets.

• When information is needed, you go


to the right filing cabinet, find the
right drawer and folder, and search
through each paper until you find
what you want.
Background and History (cont.)
• Computerized File-
based systems
• the predecessor to
databases.
• As part of a program,
files were defined for
storing data.
• Each program defined
and managed its own
data.
Background and History (cont.)
• Limitations of Computerized File- based systems:

• Separation and isolation of data.


• Each application maintained its own data storage structures.
• If you needed data that were stored in more than one application, a
programmer was often needed to extract and synchronize the data.

• Duplication of data.
• Because data were isolated, common data like customer name and
address ended up being stored in each application.
• This leads to problems with data integrity (how much the data are
“correct”) as data might be updated in one application but not another.
• Example: In a University environment, student data is stored in the
Students affairs file system and in the Library file System. A student
changes his mobile number, and one system gets updated but the other
doesn’t. Which system has the correct Mobile no?
Background and History (cont.)
• Limitations of Computerized File- based systems (cont.):

• Program-Data dependence.
• The structure and data storage are defined in each application’s code.
• changing anything about the data storage, for example, increasing the size
of the name field…requires changing all code that used any part of the file.

• Incompatible file formats.


• File structure was embedded within application programs. Two different
applications programmed with different languages are not able to read
files created by the other application.
Background and History (cont.)
• Limitations of Computerized File- based systems (cont.):

• Limited support for data integrity, file recovery


• There is no direct checking facility in the file system to ensure
validity and accuracy of data contained in a database. It must be
done through explicit programming.
• No facility to recover data lost due to system crashes.

• Heavy maintenance requirements:


• Fixed queries: You have to know the exact structure of a file in order
to query the records in that file. If the length of a field changes…all
your queries need to change!
• Rapid increase in the number of programs— Programs are written to
satisfy particular functions. Any new requirement needs a new
program.
The Database Approach
• The database approach is to separate the
data from the application. Data were
stored in one place and used as needed
by the various applications.

• One program (the Database


Management System, DBMS) managed
functions related to security, data
integrity, etc.

• Applications interact with the data in the


database by sending requests.

• Sophisticated End Users usually interact


with the DBMS in the form of an SQL
(Structured Query Language) query.
Database Management System (DBMS)

• A DBMS is a general-purpose software system that facilitates the


processes of defining, constructing and manipulating databases
for various applications.

Defining - specifying data types, structures, constraints.


Constructing - storing of data
Manipulating - querying, updating and reporting.
Database: How?
• Analysis
• Data Analysis
• What information is required by the business

• Activity Analysis
• What activities make up the business
• Design
• Logical database design to avoid data redundancy & ensure data
integrity
• Detailed system specification

• Implementation
• Create the database system

• Maintenance
• Troubleshoot, update the database
14
Data Modeling – How the programmer sees the data

• Data modeling is the first step in database system


design

• A data model is a logical description of real-world


data structures in relatively simple (graphical)
representations

• A data model serves as communications tool to


facilitate interaction among the designer, the
applications programmer, and the end user.

15
Evolution of Data Models
• Timeline

1960s 1970s 1980s 1990s 2000+

Hierarchical

Network Object-oriented

Relational Web-based
Entity-Relationship

• Each new data model capitalized on the shortcomings of


previous models 16
Entity Relationship Model - Basic Building Blocks and Symbols
• Entity
• thing about which data are to be collected and
stored, e.g. students, lecturers, courses, …
represented by a rectangle Student Course
• Attribute
• a characteristic of an entity, e.g. S_name, S_id
S_id C_id C_name
represented by an ellipse S_name
• One or more attributes form the primary key
using which an entity can be identified uniquely, Student Course
e.g. S_id. The attributes forming the primary key
are underlined in the ER model.
• Relationship
• describes an association among entities e.g.
Student takes Course
student takes course
• A relationship can have attributes
• Constraint year semester grade
• restrictions placed on the data e.g. A course is
taught by 1 lecturer
Entity Relationship Model – Types of Relationship
• A relationship can be one of
three types:
• 1:1 (one-to-one)
• 1:M(one-to-many)
• M:N(many-to-many)

• Types are written next to


each entity box.

• The type of a relationship is


determined by the rules of
the organization.
18
E-R Model: Pros & Cons
• Advantages

• Easily viewed and understood representation of database

• Can be easily translated into a relational model

• Disadvantages

• Incomplete model on its own

• Limited representational power - cannot model data constraints


not tied to entity relationships e.g. attribute constraints
19
Relational Database Model
• Dominant database model of today

• Relational Model represents how data is stored in Relational


Database

• Uses tables (relations) to represent data

• Tables
• flexible logical structure for data representation
• a series of row/column intersections
• related by sharing common entity characteristic(s)
20
STUDENT

Relational Data Model

Example: a relation STUDENT with attributes S_id, Name, Phone and age
Relational Data Model - Terminology

• Relation Schema: A relation schema is name of the relation with its attributes.
e.g.; STUDENT (S_id, Name, Phone and Age) is the relation schema for relation
(table) STUDENT.

• Column: the set of values for a particular attribute (field).

• Record (row): a group of related fields.

• Primary Key: every table (relation) in the database should have one set of
attributes which defines a row uniquely. This set of attributes is called primary
key. e.g.; S_id is the primary key of STUDENT table. A primary key is not allowed
to be NULL (empty).
Relational Data Model – Terminology (cont.)
• Field: A field is a combination of one or more related
characters or bytes and is the smallest unit of data a user
accesses. The field should contain a single value. It cannot
contain a list or multiple values
Basic properties of a field Other properties of a field
Name caption
Size Input mask
Data type Format
Default value
Required
Validation rule
Relational Data Model – Terminology (cont.)
• Data type of a field: specifies the kind of data a field can contain.
Common data types includes
• Text
• Numeric
• Date
• Currency
• Memo
• Yes/No (also called Boolean)
• Hyperlink
• Object (also called BLOB for
binary large object)
Relational Data Model – Terminology (cont.)
• Table (relation or file): is a collection of related records.
❑ Each record in the file contains the same fields.
❑ Each record in the table is UNIQUE. This is guaranteed
by the constraint on primary keys.
❑ The order of the records in a table is not significant.

• A database is a group of related data files.

• With a DBMS, users access data and set relationships


among the data in data files
Relational Database: Association among Tables (1:1 or 1:M)
• A relational database system forms relationships between tables by matching values
found in both tables. The values matched are the primary key and foreign key
values.
• To represent the relationship: a student belongs to one department , the primary
key of the DEPARTMENT table is added as a foreign key in table STUDENT

STUDENT Department
Department_code Department_name
S_id Name Phone Age D_code
COMPUTER
CS
1 John 01055123451 18 CS SCIENCE
INFORMATION
IT
TECHNOLOGY
2 Mary 01152431543 18 CS
ELECTRONICS AND
ECE COMMUNICATION
3 Tom 01256253131 20 CV
ENGINEERING
4 Bill 18 ECE CV CIVIL ENGINEERING
26
Relational Database: Association among Tables (M:N)
• To represent Many: Many relationships, e.g. a student can take many courses and a
course contains many students, a third table is TAKES is needed . Table TAKES has 5
fields : S_id, C_id, Year, Semester, Grade. S_id and C-ID are foreign keys that refer to
tables STUDENT and COURSE respectively.

STUDENT TAKES COURSE


S_id Name Phone Age C_id C_name
S_id C_id Year Sem Grade
Software Testing,
1 John 01055123451 18 CSE225 Validation, and
1 CSE320 2019 Fall
Verification
2 Mary 01152431543 18 Engineering
1 CSE012 2017 Spring A CSE012
Computation

3 Tom 01256253131 20 4 CS320 Spring B


2018 CSE320 Database Systems I

4 Bill 18 2 ASU001 2019 Fall


27ASU001 English Placement
Relational Database: Data Integrity
• Input data integrity: guaranteed by constraints on field values for
example:
• the salary level for an employee is at least $20 000 whenever salary
data is added or updated.
• The length of the phone number is exactly 11 bytes.
• The value of grade is one of {A, B, C, D, F}

• Entity integrity: guaranteed by constraints on primary key:


The primary key that identifies each record within a table is unique
and never null.

• Relationship integrity: guaranteed by constraints on foreign key:


A foreign key in a table can only contain either null values or values
from the referenced table's primary key.
28
Relational Database: Pros & Cons
• Advantages
• Structural independence
• Separation of logical database design and physical data
storage/access
• Easier database design, implementation, management, and use
• Ad hoc query capability with Structured Query Language (SQL)
• SQL translates user queries to codes

• Disadvantages
• Substantial hardware and system software overhead
• Ease-of-use allows careless use of RDBMS

29

You might also like