0% found this document useful (0 votes)
33 views101 pages

Theoretical Material Lab 1 PDF

The document outlines a Database Systems course led by Prof. Liudmyla Koliechkina, focusing on database management concepts, relational models, and SQL. It includes mandatory lab work, a project, and covers software tools like Oracle SQL Developer and Oracle Data Modeler. Students will learn to design databases, formulate SQL queries, and understand the principles of database theory and design.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views101 pages

Theoretical Material Lab 1 PDF

The document outlines a Database Systems course led by Prof. Liudmyla Koliechkina, focusing on database management concepts, relational models, and SQL. It includes mandatory lab work, a project, and covers software tools like Oracle SQL Developer and Oracle Data Modeler. Students will learn to design databases, formulate SQL queries, and understand the principles of database theory and design.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 101

Database Systems

Prof., KOLIECHKINA LIUDMYLA


Faculty of Mathematics and Computer Science
Department of Algorithms and Database
E-mail:
liudmyla.koliechkina@wmii.uni.lodz.pl
General information
Labworks – 14 (or 28 hours), project.
practical test for labwork.
The final grade consists of 50% of the lab
works grade (test) and 50% of the grade on
the project.
Students' presence in classes is
mandatory
E-mail:
liudmyla.koliechkina@wmii.uni.lodz.pl
2
Short description:
 The course familiarizes with concepts of
database management systems.
 It focuses on relational model, relational
algebra, and SQL (the standard language for
creating, querying, and modifying relational
databases).
 It also covers many aspects of database design
using Entity-Relationship-Model.

3
This course will use the software Oracle SQL Developer and
Oracle Data Modeler. 4
5
Where can you download these programs?
Oracle SQL Developer is a free, integrated development environment that simplifies
the development and management of Oracle Database.

Oracle XE (11)
https://www.oracle.com/technetwork/database/database-technologies/express-
edition/downloads/xe-prior-releases-5172097.html

SQL Developer
https://www.oracle.com/database/sqldeveloper/

Data Modeler (4.2)


https://www.oracle.com/tools/downloads/sql-data-modeler-downloads.html

You can work online (you need to create an account)(Oracle Live SQL)
https://livesql.oracle.com/apex/f?p=590:1000
During this course students will
learn:
 relational data model,
 standard SQL database language,
 Normalization of database logical
schemas and logical organization,
 basic physical data structures used in
database systems.

7
Course Content includes :
1. Overview of database systems, data models, query
languages.
2. Relational model and relational algebra.
3. Oracle Database Management System.
4. Oracle database objects (tables, integrity constraints,
indexes, views, sequences).
5. Oracle SQL Data Definition Language.
6. Common conceptual and implementation data models.
7. Designing of database system:
1) Entity-Relationship Diagrams; 2) Data normalization issues.
8. Transforming ER model into a relational database schema.
9. Oracle SQL Data Manipulation Language.
10. Introduction to PL/SQL (functions, procedures, triggers, cursors).
8
Results of this course:
1) to understand the importance of databases and their
applications
2) to have basic knowledge of the database theory
3) to know and explain basic concepts of relational
model
4) to create schemes of relational databases
5) to design a conceptual model in the form of an
Entity- Relationship diagram
6) to create database which is based on the given ER-
diagram
7) to create and manipulate the database objects
(tables, indexes, views, integrity constraints ) using SQL DDL
statement
9
Results of this course :
8) to formulate different SQL queries and data
manipulation statements
9) to create basic PL/SQL procedures, functions,
triggers
10) be able to work individually and in small groups
on the given issue
11) be able to organize the learning process
12) to present the projects and justify the
chosen solutions
13) to understand the need for continuous training
14) to comply with the legal and ethical in actions

10
Topics of labs
1. ERD Entity Relationship Diagrams.
Normalization. (Labs 1-2)
2. SQL database language – basics.
SQL Data Definition. Oracle Data Modeler
(Labs 3-4)
3. Selected relational Oracle database objects
(tables, views, constraints, indexes,
sequences) and can be created using
Oracle SQL dialect (Labs 5, 6, 7)

11
Topics of labs
4. Data Definition Language - DDL
Data manipulation Language - DML
DQL query Language - SELECT
statement (Labs 7, 8)
5. Creature basic PL/SQL procedures
Creature basic PL/SQL functions
Creature basic PL/SQL triggers
(Labs 8-14)

12
Outline
1. Basic database information
2. Basic concepts and definitions
3. Database schema
4. Entity/Relationship Modelling
5. Relationships and Diagramming
Relationships

13
1.Basic database information

Relationships with reality

Users Data source


Database
What is a
databases???
A database is an organized collection of data,
14
stored and accessed electronically from a computer system.
Database History. The sizes, capabilities, and performance of
databases and their respective DBMSs have grown in orders of
magnitude. These performance increases were enabled by the
technology progress in the areas of processors, computer memory,
computer storage, and computer networks.

Data
Storage and retrieval
entry

15
Query processing Sorting
HUMAN
RESOURCES

LIBRARY DEAN'S OFFICE

examples of using databases

Database designers organize the data to model aspects of


reality in a way that supports16processes requiring
Database
 A database-management system (DBMS) is
a computer-software application that
interacts with end-users, other
applications, and the database itself to
capture and analyze data.

 A general-aim DBMS allows the definition,


creation, querying, update, and administration
of databases.

17
 Well-known DBMSs include MySQL,
PostgreSQL, MongoDB, MariaDB,
Microsoft SQL Server, Oracle,
Sybase, SAP HANA, MemSQL,
SQLite and IBM DB2.

 consider their characteristics

18
MySQL
MySQL is a full-
featured relational
database
management
system (RDBMS)
that competes with
the likes of Oracle
DB and
Microsoft’s SQL
Server.

19
SQL Server is
Microsoft's
relational database
management
system (RDBMS).
It is a full-featured
database primarily
designed to
compete against
competitors Oracle
Database (DB) and
MySQL.
20
https://www.oracle.com/database/sqldeveloper/

Oracle database (Oracle DB) is a relational database management


system (RDBMS) from the Oracle Corporation.

21
What does Oracle Database
(Oracle DB) mean?
Oracle database
originally developed
in 1977 by
Lawrence Ellison
and other
developers, Oracle
DB is one of the
most trusted and
widely-used
relational database
engines.

22
The system is built around a relational database framework in which data
objects may be directly accessed by users through structured query
language (SQL). 23
Oracle Corporation is an American multinational computer
technology corporation headquartered in Redwood Shores, California.

In 2018, Oracle was the third-largest software company by revenue.


24
https://www.mongodb.com/what-
is-mongodb

database-management system
(DBMS) 25
 MemSQL is a distributed, in-
memory, SQL database management
system. It is a relational database
management system(RDBMS).
 On April 23, 2013, MemSQL launched its
first generally available version of the
database to the public.
26
27
28
 Sybase is a computer software company
that develops and sells database
management system (DBMS)
and middleware products.
 The company was founded in 1984 in
California.
 Sybase was the first enterprise DBMS for
the Linux operating system.

29
30
 SAP HANA is an in-memory, column-
oriented, relational database management
system developed and marketed by SAP
SE.
 Its primary function as a database server is to
store and retrieve data as requested by the
applications.
 In addition, it performs advanced analytics
(predictive analytics, spatial data processing,
text analytics, text search, streaming
analytics, graph data processing).
31
2. Basic concepts and
definitions/1
 Information
 Data
 Table, columns, and rows
 Data types

32
2. Basic concepts and
definitions/2
Information is stimuli that has
meaning in some context for its
receiver.
When information is entered into and
stored in a computer, it is generally
referred to as data.
After processing (such as formatting
and printing), output data can again
be perceived as information.
33
The concept of data is
commonly associated with
scientific research, data is collected by a
large range of organizations and
institutions, including businesses (e.g., sales
data, revenue, profits, stock price),
 governments (e.g., crime rates,
unemployment rates, literacy rates) and
 non-governmental organizations (e.g.,
censuses of the number of homeless
people by non-profit organizations).

34
Elements of a table
Data in Table

36
Database Concepts
 Database – a collection of related tables.
 Tables – a collection of related records
– collection of related entities.
 Record – collection of fields (table row)
–represents an entity.
 Field – collection of characters (table
column) – represents an attribute.
 Character – single alphabetic, numeric or
other symbol.

37
Databases
 A bunch of tables form a database
Customer Table Order Table

Product Table

 A database can represent a single


business or an entire market
Databases
 Databases are not just a bunch of
tables
Orders
OID CID PID Quantity
001 508 199 500,000
002 508 201 2
003 510 201 1

Customers Products
CID FName LName Address PID Description Cost
508 Eric Breimer ... 199 Viagra $45.99
509 Andrew Zych ... 200 Tooth Paste $2.58
510 Greg Smith ... 201 Hair Gel $5.99

 A database also includes relationships


between the different tables
39
Simple data types
Data Type Used for Example
String Alphanumeric hello world,
characters Alice,Bob123
Integer Whole numbers 7, 12, 999
Float Number with a decimal point 3.15, 9.06, 00.13
(floating point)
Character Encoding text numerically 97 (in ASCII, 97
is a
lower case 'a')
Boolean Representing logical values TRUE, FALSE

40
Data types in tables
 BYTE data type Stores any kind of binary data, up to 231 bytes
in length
 CHAR(n) data type Stores character strings; collation is in
code-set order
 CHARACTER(n) data type Is a synonym for CHAR
 CHARACTER VARYING(m,r) data type Stores character
strings of varying length (ANSI-compliant); collation is in code-
set order
 DATE type Stores calendar dates DATETIME data type Stores
calendar date combined with time of day DEC data type Is a
synonym for DECIMAL
 DECIMAL Stores floating-point numbers with definable
precision; if database is ANSI-compliant, the scale is zero
41
3. Database schema

 The database schema of a database


system is its structure described in a
formal language supported by the
database management system (DBMS).

42
“Schema" may be divided into database tables in the case of relational
databases
43
44
45
46
Abstract Concepts
 Entity – person, place, object or
event – stored as a record or a table
row

 Attribute – characteristic of an entity

– stored as field or table column

47
 Conceptual design
 Build a model independent of the
choice of DBMS
 Logical design
 Create the database in a given DBMS
 Physical design
 How the database is stored in
hardware

48
4.Entity/Relationship
Modelling
 Entity–relationship modeling was
developed for database design by Peter
Chen and published in 1976.
 However, variants of the idea existed
previously.
 Some ER modelers show super and subtype
entities connected by generalization-
specialization relationships, and an ER
model can be used also in the specification
of domain-specific ontologies.
49
 An entity–relationship model (ER
model) describes inter-related things of
interest in a specific domain of
knowledge.
 An ER model is composed of entity
types (which classify the things of
interest) and specifies relationships that
can exist between instances of those
entity types.

50
Definition 1.
The Entity-Relationship (ER) model,
a high-level data model that is useful in
developing a conceptual design for a
database.

51
Entity
Definition 2
An entity is a real-world item or concept that
exists on its own. The set of all possible
values for an entity is the entity type.

 In an ER model, we diagram an entity type as


a rectangle containing the type name, such
as student (see Figure 1).
52
Entities are the basic objects of
ERDs.
 These are the tables of your database. Entity
are nouns and the types usually fall into five
classes. Concepts, location, roles, events or
things.
 For example: students, courses, books, campus,
employees, payment, projects. Specific example of
an entity is called an instance. Each isntance
becomes a record or a row in a table.
 For example, the student John Smith is a record in
a table called students.

53
Attribute
 Each entity has attributes, or particular
properties that describe the entity.

 Definition 3
An attribute of an entity is a particular
property that describes the entity. The
set of all possible values of an attribute
is the attribute domain.

54
 Definition 4
Null (0) is the special attribute value that
indicates an unknown or missing value.

 An attribute can be simple or composite.


A simple attribute, such as grade, is one
component that is atomic. If we consider the
name in two parts, last name and first name,
then the name attribute is a composite.
55
 Definition 5
A simple attribute is one component
that is atomic.
A composite attribute has multiple
components, each of which is atomic or
composite.

56
 Figure 3. ER diagram notation for
composite attribute domain, name

57
 Attributes are facts or description of
entities. They are also often nouns and
become the columns of the table.
 For example, for entity student, the
attributes can be first name, last name,
email, address and phone numbers.

58
basic concepts in building relationships

 Primary Key
 Foreign key
 Relationships

59
Primary Key

 Primary Key* or identifier is an


attribute or a set of attributes that
uniquely identifies an instance of the
entity.

27
For example,
 for a student entity, student number is
the primary key since no two students
have the same student number.
 We can have only one primary key in
a table. It identify uniquely every row
and it cannot be null.

61
Foreign key
 A foreign key+ (sometimes called a
referencing key) is a key used to link two
tables together.
 Typically you take the primary key field
from one table and insert it into the other
table where it becomes a foreign key (it
remains a primary key in the original
table).
 We can have more than one foreign key in
a table.
28
Relationships

 Relationships are the associations


between the entities.
 Verbs often describe relationships
between entities. We will use Crow's
Foot Symbols to represent the
relationships.

63
Entity/Relationship Modelling
 E/R Modelling is used for conceptual
design
 Entities - objects or items of interest
 Attributes - facts about, or properties
of, an entity
 Relationships - links between entities

64
Example 1 (similar examples - on the lab)
The craft trading website is setting up a database to record
sellers and their products.
This requires recording the following information:
For each seller, their name, contact email, and postal
address.
For each product, its name, price, and number available.
Which product is from which seller.
A unique id number for each product.
Draw an entity-relationship (ER) diagram that
represents this information. Make sure to capture the
constraints on the relationships involved, and designate
appropriate primary keys for the entities.

65
Example 2
In a University we can have entities
for Students, Modules and Lecturers.
Students can have attributes such
as their ID, Name, and Course, and
can have relationships with Modules
(enrolment) and Lecturers (tutor).

66
Entity/Relationship Diagrams
 E/R Models are often
Lecturer ID
represented as E/R
diagrams that Name Course
 Give a conceptual
view of the database
Tutors Student
 Are independent of
the choice of DBMS

Module Studies

67
Entities
 Entities represent  Entities have
objects or things of  A general type or
interest class, such as
 Physical things like Lecturer or Module
students, lecturers,  Instances of that
employees, products particular type, such
 More abstract things as Steve Mills, are
like modules, orders, instances of Lecturer
courses, projects  Attributes (such as
name, email,
address)

60
Diagramming Entities
 In an E/R Diagram,
Lecturer ID
an entity is usually
drawn as a box with Name Course

rounded corners
 The box is labelled Tutors Student
with the name of the
class of objects
represented by that
entity Module Studies

69
Attributes
 Attributes are facts, aspects,
properties, or details about an
entity
 Students have IDs, names, courses,
addresses, …
 Modules have codes, titles, credit
weights, levels, …

70
Attributes have:
 A name
 An associated entity
 Domains of possible values
 Values from the domain for each
instance of the entity they are belong to

71
Diagramming Attributes
 In an E/R Diagram
Lecturer ID
attributes may be
drawn as ovals Name Course

 Each attribute is
linked to its entity by Tutors Student
a line
 The name of the
attribute is written in
Module Studies
the oval

72
Conclusions on the fourth topic
 An entity–relationship model (ER
model) describes inter-related things of
interest in a specific domain of
knowledge.
 An ER model is composed of entity
types (which classify the things of
interest) and specifies relationships that
can exist between instances of those
entity types.

73
5.Relationships and
Diagramming Relationships
 Relationships are an  Relationships have
association between  A name
two or more entities  A set of entities that
 Each Student takes participate in them
several Modules  A degree is the
 Each Module is taught number of entities
by a Lecturer that participate (most
 Each Employee works have degree 2)
for a single Department  A cardinality ratio

74
Cardinality Ratios
 Each entity in a relationship
can participate in zero, one, or
more than one instances of that
relationship
 This leads to 3 types of
relationship…

75
 One to one (1:1)
 Each lecturer has his office
 One to many (1:M)
 A lecturer may teach many students,
but each student has just one tutor
 Many to many (M:M)
 Each student takes several modules,
and each module is taken by several
students

76
Example 3
 A university consists of a number of departments.
 Each department offers several courses.
 A number of modules make up each course.
 Students enrol in a particular course and take
modules towards the completion of that course.
 Each module is taught by a lecturer from the
appropriate department, and each lecturer tutors a
group of students

77
Example - Entities
 A university consists of a number of
departments.
 Each department offers several courses.
 A number of modules make up each course.
 Students enrol in a particular course and take
modules towards the completion of that course.
 Each module is taught by a lecturer from the
appropriate department, and each lecturer tutors
a group of students

78
Example - Relationships
 A university consists of a number of
departments.
 Each department offers several courses.
 A number of modules make up each course.
 Students enrol in a particular course and take
modules towards the completion of that course.
 Each module is taught by a lecturer from the
appropriate department, and each lecturer
tutors a group of students

79
Example - E/R Diagram
Entities: Department, Course, Module, Lecturer, Student

Department

Course Module Lecturer

Student

80
Example - E/R Diagram
Each department offers several courses

Offers Department

Course Module Lecturer

Student

81
Example - E/R Diagram
A number of modules make up each courses

Offers Department

Course Includes Module Lecturer

Student

82
Example - E/R Diagram
Students enrol in a particular course

Offers Department

Course Includes Module Lecturer

Enrols In Student

83
Example - E/R Diagram
Students … take modules

Offers Department

Course Includes Module Lecturer

Takes

Enrols In Student

84
Example - E/R Diagram
Each module is taught by a lecturer

Offers Department

Course Includes Module Teaches Lecturer

Takes

Enrols In Student

85
Example - E/R Diagram
a lecturer from the appropriate department

Offers Department Employs

Course Includes Module Teaches Lecturer

Takes

Enrols In Student

86
Example - E/R Diagram
each lecturer tutors a group of students

Offers Department Employs

Course Includes Module Teaches Lecturer

Takes

Enrols In Student Tutors

87
Example - E/R Diagram

Offers Department Employs

Course Includes Module Teaches Lecturer

Takes

Enrols In Student Tutors

88
Example 4
We want to represent information about
products in a database.
Each product has a description, a price and
a supplier.
Suppliers have addresses, phone numbers,
and names.
Each address is made up of a street
address, a city, and a postcode.

89
Example - Entities/Attributes
 Entities or attributes:  Products, suppliers,
 product and addresses all
 description have smaller parts
 price so we can make
 supplier
 address
them entities
 phone number  The others have no
 name smaller parts and
 street address

belong to a single
city
 postcode
entity

90
Example - E/R Diagram
Price

Description Product

Street address

Name Supplier Address City

Phone number Postcode

91
Example - Relationships
 Each product has a  Each supplier has an
supplier address
 Each product has a  A supplier has a
single supplier but single address
there is nothing to  It does not seem
stop a supplier sensible for two
supplying many different suppliers to
products have the same
 A many to one address
relationship  A one to one
relationship

92
Example - E/R Diagram
Price

Description Product

Has A Street address

Name Supplier Has A Address City

Phone number Postcode

93
Once again I want to say about the types of

One to One Relationships


 Some relationships  Example - the supplier-
between entities, A address relationship
and B, might be  Is one to one
redundant if  Every supplier
 It is a 1:1 relationship
between A and B has an address
 Every A is related to a  We don’t need addresses
B and every B is that are not related to a
related to an A supplier

94
Redundant
Relationships
 We can merge the
a x
two entities that
take part in a b A B y
redundant
relationship together c z
 They become a single
entity
 The new entity has all a x

the attributes of the


old one b AB y

c z

95
Example - E/R Diagram
Price

Description Product

Has A

Name Supplier City

Phone number Postcode Street address

96
Recursive
Recursion (adjective: recursive) occurs when a
thing is defined in terms of itself or of its type.

EMPLOYEE
supervises

is supervised by

97
How to Model Relationships?

Orders
OID CID PID Quantity
001 508 199 500,000
002 508 201 2
003 510 201 1

Customers Products
CID FName LName Address PID Description Cost
508 Eric Breimer ... 199 Viagra $45.99
509 Andrew Zych ... 200 Tooth Paste $2.58
510 Greg Smith ... 201 Hair Gel $5.99

you have to define keys in tables and build relationships

98
Essential elements
of the database definition
 The database schema
 Schema objects
 Tables
 Fields and columns
 Records and rows
 Keys
 Relationships
 Data types
99
Bibliography:
1. Hector Garcia-Molina, Jeffrey D. Ullman, Jennifer
Widom, "Database System Implementation".
2. R. Barker, "CASE Method: Entity Relationship
Modelling (Computer Aided Systems Engineering)".
3. Michael J. Hernandez, "Database Design for Mere
Mortals®: A Hands-On Guide to Relational
Database Design"
4. D.Stamper, W.Price: "Database design and
management: An applied aproach".
5. J.Watson : "Oracle Database 10g OCP all-in-one".
Bibliography:

6. Jason Price, „Oracle Database 11g i SQL. Programowanie”,


Helion 2009
7. 6.Oracle® Database SQL Language Reference 11g Release 2
(11.2) E41084-03 (pdf)
8. https://docs.oracle.com/cd/E11882_01/server.112/e41084.pdf
9. "External table". Oracle FAQ. Oracle FAQ. 2015. Retrieved
2015-08-14.
10.Bryla, Bob; Thomas, Biju (2006). OCP: Oracle 10g New
Features for Administrators Study Guide: Exam 1Z0-040. John
Wiley & Sons. p. 90. ISBN 9780782150858. Retrieved 2015-08-
14.
11.https://www.techonthenet.com/oracle/datatypes.php
12.https://docs.oracle.com/cd/B28359_01/server.111/b28318/
datatype.htm#CNCPT012
101

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy