You are on page 1of 21

Dr. Moussa Demba Aljouf University- College of Computer and Information Science, Sakaka.

1
Databases CSC325














Dr. Moussa Demba Aljouf University- College of Computer and Information Science, Sakaka.
2
References:
1. i,.I l. iIl> . SQL aI l.l,.I ic ,,o.
2. lo,o. L ,s.VaI l.l,.I ic l.o , ., .,I . .,LII i.c .
3. Fundamentals of database systems, fourth edition, Elmasri and Navathe.
4. Database systems, A pratical approach to design, implementation, and
management, Fourth edition, T. Connolly and C. Begg.

Teaching Scheme:
Chapter 1: Introduction to databases.
Chapter 2: The Entity-Relationship model.
Chapter 3: The Relational Model.
Chapter 4: Database Normalization.
Chapter 5: Physical database design-Introduction to SQL.





Dr. Moussa Demba Aljouf University- College of Computer and Information Science, Sakaka.
3


Chapter 1
Introduction to Databases


Data, Database, DBMS, DB system
Application program
Contrasting File and database systems
Data dictionary
Sql : DDL, DML
Database schema : 3-level architecture
Logical & physical data independence
Database users



Dr. Moussa Demba Aljouf University- College of Computer and Information Science, Sakaka.
4
Basic Definitions

What is Data? Known facts that can be recorded and have an implicit
meaning. l.c Va.. lIl> ILoI l.l,.I l _ l.l,.I .
And where is it now? Data is stored in many places, including our heads.
you can find it in:







Example:






student names: salah, mohamed, omar,
student grades: A, B, B+, C,
course names : database, AI,
department names: CS,Math,Phys
etc




Dr. Moussa Demba Aljouf University- College of Computer and Information Science, Sakaka.
5
What is a Database?
Is a collection of related data (information) stored on a computer.
Example of DataBase: Part of a university.









Level
CourseNumber
325
242
363



Dr. Moussa Demba Aljouf University- College of Computer and Information Science, Sakaka.
6
Example of a Database (Continued)

Entities: l:l,S
STUDENTs
COURSEs
GRADE_REPORT
DEPARTMENTs
TEACHERs

Relationships between entities:
STUDENTs enroll COURSES
COURSEs have prerequisite COURSEs
TEACHERs teach COURSEs
COURSEs are offered by DEPARTMENTs
- etc
Attributes or columns:-'~=
Name, StudentNumber, CourseNumber, Level, Age, Grade,.





Dr. Moussa Demba Aljouf University- College of Computer and Information Science, Sakaka.
7
Basic Definitions (continued)
Database-System Applications: Databases are widely used. Here
are some representative applications:
l:l,; cg8 la,;b: : i. l..o, l.l,.I ic ls,.L. _,. _o :

Banks g.; : all transactions ( --= '-'-~- >-'-- ),
Airlines gb> jg> : reservation (_>>), schedules ( > ),
University nol> : registration (_,>a:), grades ( > l ),
Sales ln,;o: customers (_:l;_), purchases (_a),
Manufacturing g,.:: production (g.), inventory (_>o g>go),
Human resources j_a; go : employees (Q--=;--),salaries
{ :_ u ), tax deduction (--,~- ;~=),
Telecommunication: for keeping records of calls made,
generating monthly bills, storing information about
the communication networks.

Databases touch all aspects of our lives.






Dr. Moussa Demba Aljouf University- College of Computer and Information Science, Sakaka.
8
Database Management System (DBMS): is a software system
designed to store, manage, and facilitate access to databases.
l:l,; cl8 lb: : ic _,>.I oooI l,>o.I lL.
l.l,.I .
l.. lo l.l,. icl >Ilao . _o.I co>o loi>.. _o, _.I _
ia.o _>o. lL. V c .,a. _., >Ilao l.. DBNS lL.
sI.>oI ls,.L.II l.l,.I ic .
Examples of DBMS: Access, Oracle, MySQL, SyBase, SQL Server,
DBMS Manages Interaction :


Before database management systems (DBMSs) came along,
organizations usually stored information in files.




Dr. Moussa Demba Aljouf University- College of Computer and Information Science, Sakaka.
9
File-based System v. Database System


Application Program (AP):
Is a computer program that interacts with the DB by issuing
an appropriate request, typically an SQL statement, to the DBMS.







AP1
AP2
AP3
AP1
AP2
AP3



Dr. Moussa Demba Aljouf University- College of Computer and Information Science, Sakaka.
10
File-based System: each AP defines and manages its own data.
- ol:_; _ AP l> :l:l,; _jj _nj .
- j> oo _ ,a.. j> ol:_; ;l.S >l> l. .
DB system: storage of the data is now managed by the DBMS.


Database System Environment





s Hardware: Systems Physical devices
Computers
Peripherals
Network




Dr. Moussa Demba Aljouf University- College of Computer and Information Science, Sakaka.
11



















Software
Operating system: manages hardware components
DBMS: manages database
MS Access, SQL Server, Oracle, DB2
Application and utility software: support access and manipulate data
Generate information for decision making
Help to manage database system
People (five users)
System administrator : hardware system support
Database administrator: manage DBMS use
Database designer: design database structure
System analysis and programmers: implement application programs
End users:
Procedures
Instruction and rule that govern the design and use of the database
system



Dr. Moussa Demba Aljouf University- College of Computer and Information Science, Sakaka.
12
File System Critique :


Data separation and isolation l.l,.I c _
Limited Sharing l.o i>o
Limited data security i>o l.l,.I ,. _o
Data duplication l.l,.I .
Incompatible data (different file formats)
(_.I sI.>o lsIo) .l,.I l _. _.l>. ic
Etc
Some Database advantages:
Sharing of data l.l,.I l.o
Compatible data l.l,.I _. _.l>.
Integrity of data oV. l.l,.I
Security of data l.l,.I ,. _o
Minimal data redundancy i. l.l,.I .
Immediate update of data i,i>. l.l,.I
etc





Dr. Moussa Demba Aljouf University- College of Computer and Information Science, Sakaka.
13
So why not use database always?
Given all these advantages, is there ever a reason
not to use a DBMS? Sometimes, yes.

Expensive/complicated to set up and maintain.
(this cost & complexity must be offset by need.)
the amount of effort needed to transfer data into the
database from a current system,
the impact on the whole company if the database fails
(even if only for a relatively short period).

DBMS Functionality (DBMS J-~-)
Define a database : in terms of data types, structures and
constraints. ---=- --'- '-'-- Q- ~-= ;- '-'--- ')-'- ;---
Construct or Load the Database: on a secondary storage
medium. '-- .,-=- -=' '-',-' : _'= ,=-' ,,-'`' =-,--'
Manipulating the database : querying, generating reports,
insertions, deletions and modifications to its content
Hh =' , -= '-',-' : `--` _-,, -=' '= `,--
Protection or Security: measures to prevent unauthorized access
,--- -'=-
SQL

SQL has 2 major components :
Data Definition Language (DDL) : for defining the DB structure
and controlling access to the data.

Data Manipulation Language (DML): for retrieving and updating
data.



Dr. Moussa Demba Aljouf University- College of Computer and Information Science, Sakaka.
14

Data Definition Language (DDL)
- ~-,- ) ~~ ( '-'---
Specification notation for defining the database
schema (i.e. to define or modify the DB schema).
It can not be used to manipulate data.
' -- DDL '--` .`- '--` ,'-- -'=' -` CREATE
-=' - DROP .,--'- ALTER --,'-
.DESCRIBE
V Q--- ')--=-~ '-'--- =-'-- .
Example: CREATE table account (
account-number char(10) not NULL,
balance integer);
account-number and balance : _.l>
Null : unknown, ,c aoI ,,sI _c
DDL compiler generates a set of tables stored in a
data dictionary or system catalog ,''- '=- ,-'




Dr. Moussa Demba Aljouf University- College of Computer and Information Science, Sakaka.
15
System Catalog (;-'- '=-)
Is a repository of information describing the data in the
DB: its the data about the date or metadata
( '-',-' = '-,'-).
For example, the system catalog stores:
names, types and sizes (-) of data items;
names of relationships;
integrity constraints on the data;
names of authorized users who have access to the
data;
the data items that each can access and the type of
access allowed; for example, insert, delete, update,
or select;






Dr. Moussa Demba Aljouf University- College of Computer and Information Science, Sakaka.
16








Illustrating metadata with Sql Server Express



Dr. Moussa Demba Aljouf University- College of Computer and Information Science, Sakaka.
17
Data Manipulation Language (DML)
n >lno ; l:l,
Language for accessing and manipulating the data organized by
the appropriate data model (i.e. read and update the DB)
DML also known as query language
'=` - .`- '-',-' '-- ','-- -'=' -` DML ' --
UPDATE -,-=-'- SELECT =--`- INSERT
.DELETE -=' -
Example :
INSERT INTO account VALUES
(132456780, 1500) ;
SELECT * FROM account;

:==>-
,- Q--- SQL J-- =-,-- '- - PL/SQL C++ Java
VB , ''=' -- ' --- -' '- --~- .{host languages)






Dr. Moussa Demba Aljouf University- College of Computer and Information Science, Sakaka.
18
Database Schema l:l,; cl8 bb>o





An architecture for a DB system (the 3-level architecture)

View level or external schema: describe how users see the data.
The external schema design is guided by end user requirements. For
example, we might want to allow students to find out the names of
faculty members teaching courses as well as course credits. This can be
done by defining the following view:

Courseinfo( cid: string, fname: string, credits: integer)

USERS



Conceptual Schema
Physical Schema
External Schema



Dr. Moussa Demba Aljouf University- College of Computer and Information Science, Sakaka.
19
A user can treat a view just like a relation and ask questions about the
records in the view. Even though the records in the view are not stored
explicitly, they are computed as needed.

Logical level or conceptual schema: describes entities, data types,
relationships, user operations, and constraints (data stored and the
relationships among them).
In our sample university database, these relations contain information
About entities, such as students and courses, and about relationships,
such as students' enrollment in courses.

Students(sid: string, name: string, login: string, age: integer, gpa: real)
Courses( cid: string, cname: string, credits: integer)
Enrolled (sid: string, cid: string, grade: string)
Faculty(fid: string, fname: string, sal: real)

Physical level or physical schema: its the one concerned with the way
the data is physically stored










Dr. Moussa Demba Aljouf University- College of Computer and Information Science, Sakaka.
20
Example: Difference between the three levels



Age DOB Name DOB Name Number


Sex Grade PlaceOfBirth DOB Name Number


Struct Student{
int Number;
char Grade;
char Name[20];
char DateOfBirth[20];
char Sex;
char PlaceOfBirth[30]
}





Physical
level
Logical
level
view 1
view 2
Logical data independence
Physical data independence




Dr. Moussa Demba Aljouf University- College of Computer and Information Science, Sakaka.
21
Logical data independence: is the capacity to change
(adding or removing data items) the conceptual schema
without having to change external schemas or AP.

Physical data independence: is the capacity to change
(using different storage structures) the physical schema
without having to change the conceptual or external
schemas.









END.

You might also like