Database-Systems-Overview
Database-Systems-Overview
9. Stored Procedures
10. Views
11. Triggers
12. Transactions and Isolation Levels
13. NoSQL Databases
3
RDBMS Systems
Relational Databases, Database Servers and RDBMS
Relational Databases
Database models
Hierarchical (tree)
Network / graph
Relational (tables)
Object-oriented
Relational databases
Represent a bunch of tables together with the relationships between them
Rely on a strong mathematical foundation: the relational algebra
5
Relational Database Management
System
Relational Database Management Systems (RDBMS) manage data
stored in tables
RDBMS systems typically implement
Creating / altering / deleting tables and relationships between them
(database schema)
Adding, changing, deleting, searching and retrieving of data ows stored in
the tables
Support for the SQL language
Transaction management (optional)
6
RDBMS Systems
7
Tables and Relationships
Database Tables, Relationships, Multiplicity
Tables
Database tables consist of data, arranged in rows and columns
For example (table Persons):
Persons (
Id: number,
FirstName: string,
LastName: string,
Employer: string
)
10
Primary Key
12
Relationships (2)
14
Relationships' Multiplicity – Many-To-
Many
Relationship many-to-many
Records in the first table have many corresponding records in the second one and vice versa
Implemented through additional table
Students StudentsCourses
Id Name
StudentId CourseId Courses
1 1 Id Name
1 Pesho
1 2
2 Minka 1 .NET
3 2
3 Gosho 2 Databases
3 3
4 Jivka 3 JavaScript
4 2
15
Relationships' Multiplicity – One-To-
One
Relationship one-to-one
Docume
Pictures
nts
Birthda
y Party 17
Self-Relationships
The primary / foreign key relationships can point to one and the same
table
Example: folders hold sub-folders
Primary Foreign Self-
Key Key Relationship
Folders
Id Folder ParentId
1 Root NULL
2 Documents 1
3 Pictures 1
4 Birthday Party 3
18
E/R Diagrams
Entity / Relationship Diagrams
and DB Modeling Tools
Relational Schema
20
E/R Diagrams – Examples The diagram is
created with
Microsoft SQL
Server
Management
Studio
21
E/R Diagrams – Examples (2) The
diagram is
created
with
ERwin
22
E/R Diagrams – Examples (3)The diagram is
created with
fabFORCE DB
Designer for
MySQL
23
E/R Diagrams – Examples (4)
The diagram is
created with MS
Visio
DepartmentProfessor Person
Professor
PK,FK1 DeptId PK PersonId
PK,FK1 ProfessorId
PK,FK2 ProfessorId
Title FirstName
LastName
Course
Department
PK CourseId
PK DeptId Student
CourseName
PK,FK1 StudentId
DeptName FK1 DeptId
FK2 ProfessorId
FacultyNumber
CourseStudent
PK,FK1 StudentId
PK,FK2 CourseId
24
Tools for E/R Design
25
DB Normalization
Avoiding Duplicated Data through Database Schema Normalization
Normalization
34
Integrity Constraints (2)
name = UPPER(name) 35
Indices
36
The SQL Language
http://en.wikipedia.org/wiki/SQL#Standard
ization
SQL language supports:
Creating, altering, deleting tables and other DB objects
Searching, retrieving, inserting, modifying and deleting table data (rows)
37
The SQL Language (2)
39
Stored Procedures (2)
Views are named SQL SELECT queries which are used as tables
Simplify data access
Facilitate writing of complex SQL queries
Used also to apply security restrictions:
E.g. a certain user isn't given permissions on any of the tables in the
database
The user is given permissions on few views (subset of DB) and few stored
procedures only
41
Views – Example
Companies Towns
I Company TownI I Town County
d d d Id
1 Mente LTD 1 1 Sofia 1
2 BulkSoft 2 2 New 3
Inc. York
3 HardSoft 4 3 Moscow 2
Corp.
Countries 4 Plovdiv 1
4 Sputnik 3
Corp. I Countr
d y
1 Bulgari
a 42
2 Russia
Views – Example (2)
CREATE VIEW V_BGCompanies AS
SELECT
Companies.Id AS Id,
Companies.Company AS Company
FROM Companies INNER JOIN
(Towns INNER JOIN Countries ON
Towns.CountryId = Countries.Id)
ON Companies.TownId = Towns.Id
WHERE
Countries.Country = "Bulgaria";
Id Company
Triggers are special stored procedures that are activate when some
event occurs, for instance:
When inserting a record
When changing a record
When deleting a record
Triggers can perform additional data processing, e.g.
To change the newly added data
To maintain logs and history on change
44
Triggers – Example
END;
Transactions
ACID Transactions and Isolation
Transactions
47
DB Transactions Lifecycle
Read Write
48
Transactions Behavior
49
NoSQL Databases
Non-Relational Database Systems
Non-Relational Data Models
51
What is NoSQL Database?
52
Relational vs. NoSQL Databases
Relational databases
Data stored as table rows
Relationships between related rows
Single entity spans multiple tables
RDBMS systems are very mature, rock solid
NoSQL databases
Data stored as documents
Single entity (document) is a single record
Documents do not have a fixed structure
53
Relational vs. NoSQL
Relational Model Models
Document Model
Name Svetlin
Nakov Name: Svetlin Nakov
Gender male Gender: male
Phone +359333777 Phone: +359333777555
555
Address:
Email nakov@abv.
* - Street: Tintyava 15-17
bg1
Street
Site Tintyava 15-
www.nakov. - Post Code: 1113
17
com - Town: Sofia
Post 1113
*
1 - Country: Bulgaria
Code
Town Sofia Email: [email protected]
*
1 Site: www.nakov.com
Country Bulgaria 54
NoSQL Database Systems
Redis
Ultra-fast in-memory data structures server
MongoDB
Mature and powerful JSON-document database
CouchDB
JSON-based document database with REST API
Cassandra
Distributed wide-column database
DB Ranking: http://db-engines.com/en/ranking
55
Summary / Questions
is NoSQL database?