SlideShare a Scribd company logo
1 of 41
0© 2019, LogMeIn, Inc.
Databases
1© 2019, LogMeIn, Inc.
Databases
• Basics
• Database types
• SQL
• Indexes
• Views
• Stored procedures
• MongoDB
2© 2019, LogMeIn, Inc.
Data
• The data itself doesn’t have any meaning
– 300
– A=25
– Yellow
– [32,12,43,21,55,76,54]
3© 2019, LogMeIn, Inc.
Information
• Data with meaning
– Ferenc is 39 years old
– My neighbor has four black dogs
– My grandfather was ten years older than my grandmother.
– A rose is a woody perennial flowering plant of the genus Rosa, in the
family Rosaceae, or the flower it bears.
4© 2019, LogMeIn, Inc.
Database
• A database is an organized collection of data
5© 2019, LogMeIn, Inc.
Database management system
The database management system (DBMS) is the software that interacts
with end users, applications, and the database itself to capture and analyze
the data.
6© 2019, LogMeIn, Inc.
Relational database system
• A relational database management system (RDBMS) is a database
management system (DBMS) based on the relational model of data.
• The relational model (RM) for database management is an approach to
managing data using a structure and language consistent with first-order
predicate logic, first described in 1969 by English computer scientist Edgar
F. Codd where all data is represented in terms of tuples, grouped into
relations.
7© 2019, LogMeIn, Inc.
RDBMS
Id Title Author Year ISBN10
1 Omerta Mario Puzo 2000 0-434-00870-2
2 The Godfather Mario Puzo 1969 0-399-10342-2
3 Birdy William
Wharton
1979 0-679-73412-0
4 Slaughterhouse-
five
Kurt
Vonnegut
1969 0-7910-9295-X
Id Name Year
1 Zoltan Kovacs 1998
2 Maria Vas 2000
3 Lajos Jo 2014
4 Klara Kis 1979
8© 2019, LogMeIn, Inc.
Relational Database Management Systems
• MySQL
• PostgreSQL
• SQLServer
• Oracle RDBMS
• DB2
• Amazon Aurora
9© 2019, LogMeIn, Inc.
RDBMS’s (Pro)
• SQL is a powerful query language
• There’s a lot’s of relational databases available, with good support
• It’s easy to find a developer with SQL experience
• They’re ACID complaint
– Atomicity
– Consistency
– Isolation
– Durabilty
10© 2019, LogMeIn, Inc.
RDBMS (Con)
• The data has to be stored in a structured way, planning needed
• It’s hard to convert between database tables and real objects
• It’s hard to optimize on scaling, they’re mostly vertically scalable
11© 2019, LogMeIn, Inc.
Non-relational databases (NoSQL)
Relational databases were never designed to cope with the scale and agility
challenges that face modern applications – and aren't built to take
advantage of cheap storage and processing power that's available today
through the cloud. NoSQL tries to solve these problems.
12© 2019, LogMeIn, Inc.
Key – Value store
• Memcached
• Redis
• Amazon DynamoDB
13© 2019, LogMeIn, Inc.
Wide column store
• Apache Cassandra
• Apache HBase
14© 2019, LogMeIn, Inc.
Document Store
• MongoDB
• Couchbase
15© 2019, LogMeIn, Inc.
Graphdb
• Neo4j
16© 2019, LogMeIn, Inc.
Searchengine
• Elasticsearch
• Splunk
• Apache solr
17© 2019, LogMeIn, Inc.
Time series data
• RRDTool
• Prometheus
18© 2019, LogMeIn, Inc.
NoSQL Pros
• Flexibile Scalability
• Stores Massive Amounts of data
• Database maintenance could be easier
• Cheaper to implement
19© 2019, LogMeIn, Inc.
(Cap Theorem)
• The CAP theorem states that it is impossible for a distributed data store to
simultaneously provide more than two out of the following three
guarantees:
– Consistency: Every read receives the most recent write or an error
– Availability: Every request receives a (non-error) response – without the guarantee
that it contains the most recent write
– Partition tolerance: The system continues to operate despite an arbitrary number of
messages being dropped (or delayed) by the network between nodes
20© 2019, LogMeIn, Inc.
NoSQL Cons
• They’re not mature
• Harder to get support
• Business Analytics and Business Intelligence could be harder to
implement
21© 2019, LogMeIn, Inc.
SQL
SELECT b.title
FROM friends f
JOIN books b
ON b.year =
f.year
WHERE f.name
= ‘Klara Kis’
Id Title Author Year ISBN1
0
1 Omerta Mario
Puzo
2000 0-434-
00870-
2
2 The
Godfat
her
Mario
Puzo
1969 0-399-
10342-
2
3 Birdy William
Wharto
n
1979 0-679-
73412-
0
4 Slaught
erhous
e-five
Kurt
Vonneg
ut
1969 0-
7910-
9295-x
Id Name Year
1 Zoltan
Kovacs
1998
2 Maria
Vas
2000
3 Lajos Jo 2014
4 Klara Kis 1979
22© 2019, LogMeIn, Inc.
DDL - Data definition language
• CREATE
• ALTER
• DROP
• TRUNCATE
23© 2019, LogMeIn, Inc.
DQL - Data query language
• SELECT
• FROM
• WHERE
• GROUP BY
• ORDER BY
• HAVING
24© 2019, LogMeIn, Inc.
DML - Data Manipulation Language
• INSERT
• UPDATE
• DELETE
25© 2019, LogMeIn, Inc.
JOIN
• A JOIN clause is used to combine rows from two or more tables, based on
a related column between them.
26© 2019, LogMeIn, Inc.
INNER JOIN
SELECT * FROM friends f JOIN books b
+------+---------------+------+------+------------------+-----------------+------+---------------+
| id | Name | Year | id | Title | Author | Year | ISBN10 |
+------+---------------+------+------+------------------+-----------------+------+---------------+
| 1 | Kovacs Zoltan | 1998 | 1 | Omerta | Mario Puzo | 2000 | 0-434-00870-2 |
| 2 | Vas Maria | 2000 | 1 | Omerta | Mario Puzo | 2000 | 0-434-00870-2 |
| 3 | Jo Lajos | 2014 | 1 | Omerta | Mario Puzo | 2000 | 0-434-00870-2 |
| 4 | Kis Klara | 1979 | 1 | Omerta | Mario Puzo | 2000 | 0-434-00870-2 |
| 1 | Kovacs Zoltan | 1998 | 2 | The Godfather | Mario Puzo | 1969 | 0-399-10342-2 |
| 2 | Vas Maria | 2000 | 2 | The Godfather | Mario Puzo | 1969 | 0-399-10342-2 |
| 3 | Jo Lajos | 2014 | 2 | The Godfather | Mario Puzo | 1969 | 0-399-10342-2 |
| 4 | Kis Klara | 1979 | 2 | The Godfather | Mario Puzo | 1969 | 0-399-10342-2 |
| 1 | Kovacs Zoltan | 1998 | 3 | Birdy | William Wharton | 1979 | 0-679-73412-0 |
| 2 | Vas Maria | 2000 | 3 | Birdy | William Wharton | 1979 | 0-679-73412-0 |
| 3 | Jo Lajos | 2014 | 3 | Birdy | William Wharton | 1979 | 0-679-73412-0 |
| 4 | Kis Klara | 1979 | 3 | Birdy | William Wharton | 1979 | 0-679-73412-0 |
| 1 | Kovacs Zoltan | 1998 | 4 | Slaughterhouse-5 | Kurt Vonnegut | 1969 | 0-7910-9295-x |
| 2 | Vas Maria | 2000 | 4 | Slaughterhouse-5 | Kurt Vonnegut | 1969 | 0-7910-9295-x |
| 3 | Jo Lajos | 2014 | 4 | Slaughterhouse-5 | Kurt Vonnegut | 1969 | 0-7910-9295-x |
| 4 | Kis Klara | 1979 | 4 | Slaughterhouse-5 | Kurt Vonnegut | 1969 | 0-7910-9295-x |
+------+---------------+------+------+------------------+-----------------+------+---------------+
27© 2019, LogMeIn, Inc.
LEFT (OUTER) JOIN
mysql> SELECT * FROM friends f LEFT JOIN books b ON b.Year = f.year
+------+---------------+------+------+--------+-----------------+------+---------------+
| id | Name | Year | id | Title | Author | Year | ISBN10 |
+------+---------------+------+------+--------+-----------------+------+---------------+
| 2 | Vas Maria | 2000 | 1 | Omerta | Mario Puzo | 2000 | 0-434-00870-2 |
| 4 | Kis Klara | 1979 | 3 | Birdy | William Wharton | 1979 | 0-679-73412-0 |
| 1 | Kovacs Zoltan | 1998 | NULL | NULL | NULL | NULL | NULL |
| 3 | Jo Lajos | 2014 | NULL | NULL | NULL | NULL | NULL |
+------+---------------+------+------+--------+-----------------+------+---------------+
28© 2019, LogMeIn, Inc.
RIGHT (OUTER) JOIN
mysql> SELECT * FROM friends f RIGHT JOIN books b ON b.year = f.year
+------+-----------+------+------+------------------+-----------------+------+---------------+
| id | Name | Year | id | Title | Author | Year | ISBN10. |
+------+-----------+------+------+------------------+-----------------+------+---------------+
| 2 | Vas Maria | 2000 | 1 | Omerta | Mario Puzo | 2000 | 0-434-00870-2 |
| 4 | Kis Klara | 1979 | 3 | Birdy | William Wharton | 1979 | 0-679-73412-0 |
| NULL | NULL | NULL | 2 | The Godfather | Mario Puzo | 1969 | 0-399-10342-2 |
| NULL | NULL | NULL | 4 | Slaughterhouse-5 | Kurt Vonnegut | 1969 | 0-7910-9295-x |
+------+-----------+------+------+------------------+-----------------+------+---------------+
29© 2019, LogMeIn, Inc.
SELF JOIN
mysql> SELECT * FROM friends a JOIN friends b;
+------+---------------+------+------+---------------+------+
| id | Name | Year | id | Name | Year |
+------+---------------+------+------+---------------+------+
| 1 | Kovacs Zoltan | 1998 | 1 | Kovacs Zoltan | 1998 |
| 2 | Vas Maria | 2000 | 1 | Kovacs Zoltan | 1998 |
| 3 | Jo Lajos | 2014 | 1 | Kovacs Zoltan | 1998 |
| 4 | Kis Klara | 1979 | 1 | Kovacs Zoltan | 1998 |
| 1 | Kovacs Zoltan | 1998 | 2 | Vas Maria. | 2000 |
| 2 | Vas Maria | 2000 | 2 | Vas Maria | 2000 |
| 3 | Jo Lajos | 2014 | 2 | Vas Maria | 2000 |
| 4 | Kis Klara | 1979 | 2 | Vas Maria | 2000 |
| 1 | Kovacs Zoltan | 1998 | 3 | Jo Lajos | 2014 |
| 2 | Vas Maria | 2000 | 3 | Jo Lajos | 2014 |
| 3 | Jo Lajos | 2014 | 3 | Jo Lajos | 2014 |
| 4 | Kis Klara | 1979 | 3 | Jo Lajos | 2014 |
| 1 | Kovacs Zoltan | 1998 | 4 | Kis Klara. | 1979 |
| 2 | Vas Maria | 2000 | 4 | Kis Klara | 1979 |
| 3 | Jo Lajos | 2014 | 4 | Kis Klara | 1979 |
| 4 | Kis Klara | 1979 | 4 | Kis Klara | 1979 |
+------+---------------+------+------+---------------+------+
30© 2019, LogMeIn, Inc.
Indexes
mysql> SHOW CREATE TABLE neos_largeG
*************************** 1. row ***************************
Table: neos_large
Create Table: CREATE TABLE `neos_large` (
`id` int(11) DEFAULT NULL,
[...]
`ink` double DEFAULT NULL,
`om` double DEFAULT NULL,
`w` double DEFAULT NULL,
KEY `tau` (`tau`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
mysql> SELECT COUNT(*) FROM neos_large;
+----------+
| COUNT(*) |
+----------+
| 18254688 |
+----------+
1 row in set (4.04 sec)
31© 2019, LogMeIn, Inc.
Indexes
mysql> SELECT MAX(ink) FROM neos_large;
+-------------------+
| MAX(ink) |
+-------------------+
| 154.3668580789491 |
+-------------------+
1 row in set (5.10 sec)
mysql> ALTER TABLE neos_large ADD INDEX(ink);
Query OK, 0 rows affected (44.76 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> SELECT MAX(ink) FROM neos_large;
+-------------------+
| MAX(ink) |
+-------------------+
| 154.3668580789491 |
+-------------------+
1 row in set (0.00 sec)
32© 2019, LogMeIn, Inc.
Views
mysql> CREATE VIEW neos_ink AS SELECT id, ink FROM neos_large;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT * FROM neos_ink LIMIT 5;
+----+---------------------+
| id | ink |
+----+---------------------+
| 1 | 10.82856921420592 |
| 2 | 11.56484503237207 |
| 3 | 9.384537356044309 |
| 4 | 26.68761210417409 |
| 5 | 11.87652956555689 |
+----+---------------------+
5 rows in set (0.00 sec)
33© 2019, LogMeIn, Inc.
Stored procedures
DELIMITER $$
DROP PROCEDURE IF EXISTS duplicate_rows$$
CREATE PROCEDURE duplicate_rows (
IN tablename VARCHAR(255),
IN times INT
)
BEGIN
SET @statement = CONCAT(CONCAT(CONCAT(CONCAT("INSERT INTO ",tablename),"
SELECT * FROM "),tablename),";");
PREPARE stmt FROM @statement;
WHILE times > 0 DO SELECT times as "Remaining";
EXECUTE stmt;
SET times = times - 1;
END WHILE;
DEALLOCATE PREPARE stmt;
END $$
34© 2019, LogMeIn, Inc.
Functions
CREATE FUNCTION circle_area (radius REAL)
RETURNS REAL DETERMINISTIC
RETURN POW(radius,2) * PI();
CREATE FUNCTION circle_circumference (radius REAL)
RETURNS REAL DETERMINISTIC
RETURN radius * 2 * PI();
35© 2019, LogMeIn, Inc.
Triggers
DELIMITER $$
CREATE TRIGGER remove_credit_card
BEFORE INSERT ON users FOR EACH ROW
BEGIN
IF new.credit_card_number = '' THEN
SET credit_card_number = NULL;
END IF;
END
$$
36© 2019, LogMeIn, Inc.
MongoDB
“MongoDB is a document database with the scalability and flexibility that you
want with the querying and indexing that you need”
37© 2019, LogMeIn, Inc.
INSERT
db.konyvek.insert(
[
{ Cim: "Omerta", Szerzo: "Mario Puzo", Ev: 2000, ISBN10:
"0-434-00870-2"},
{ Cim: "The Godfather", Szerzo: "Mario Puzo", Ev: 1969,
ISBN10: "0-399-10342-2"},
{ Cim: "Birdy", Szerzo: "William Wharton", Ev: 1979,
ISBN10: "0-679-73412-0"},
{ Cim: "Slaughterhouse-five", Szerzo: "Kurt Vonnegut ", Ev:
2000, ISBN10: "0-7910-9295-x"}
]
)
38© 2019, LogMeIn, Inc.
Find
> db.konyvek.find(
{Cim: "Slaughterhouse-five"}
)
{ "_id" : ObjectId("5c927003d9e410e1bb9fa583"), "Cim" :
"Slaughterhouse-five", "Szerzo" : "Kurt Vonnegut ", "Ev" :
2000, "ISBN10" : "0-7910-9295-x" }
39© 2019, LogMeIn, Inc.
Update
> db.konyvek.update(
{ISBN10: "0-7910-9295-x"},
{Cim: "Slaughterhouse-five", Szerzo: "Kurt Vonnegut ", Ev:
2000, ISBN10: "0-7910-9295-X"}
)
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" :
1 })
40© 2019, LogMeIn, Inc.
“Schemaless”
> db.konyvek.update({"Cim" : "Slaughterhouse-five", "Szerzo" : "Kurt Vonnegut ",
"Ev" : 1969, "ISBN10" : "0-7910-9295-x"},{"Cim" : "Slaughterhouse-five", "Szerzo"
: "Kurt Vonnegut ", "Ev" : 2000, "ISBN10" : "0-7910-9295-X", ISBN13: "978-0-7910-
9295-8"})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.konyvek.find()
{ "_id" : ObjectId("5c929445345a87cb9fea0bc1"), "Cim" : "Omerta", "Szerzo" :
"Mario Puzo", "Ev" : 2000, "ISBN10" : "0-434-00870-2" }
{ "_id" : ObjectId("5c929445345a87cb9fea0bc2"), "Cim" : "The Godfather", "Szerzo"
: "Mario Puzo", "Ev" : 1969, "ISBN10" : "0-399-10342-2" }
{ "_id" : ObjectId("5c929445345a87cb9fea0bc3"), "Cim" : "Birdy", "Szerzo" :
"William Wharton", "Ev" : 1979, "ISBN10" : "0-679-73412-0" }
{ "_id" : ObjectId("5c929445345a87cb9fea0bc4"), "Cim" : "Slaughterhouse-five",
"Szerzo" : "Kurt Vonnegut ", "Ev" : 1969, "ISBN10" : "0-7910-9295-X", "ISBN13" :
"978-0-7910-9295-8" }

More Related Content

Recently uploaded

Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 

Recently uploaded (20)

Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 

Featured

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 

Databases

  • 1. 0© 2019, LogMeIn, Inc. Databases
  • 2. 1© 2019, LogMeIn, Inc. Databases • Basics • Database types • SQL • Indexes • Views • Stored procedures • MongoDB
  • 3. 2© 2019, LogMeIn, Inc. Data • The data itself doesn’t have any meaning – 300 – A=25 – Yellow – [32,12,43,21,55,76,54]
  • 4. 3© 2019, LogMeIn, Inc. Information • Data with meaning – Ferenc is 39 years old – My neighbor has four black dogs – My grandfather was ten years older than my grandmother. – A rose is a woody perennial flowering plant of the genus Rosa, in the family Rosaceae, or the flower it bears.
  • 5. 4© 2019, LogMeIn, Inc. Database • A database is an organized collection of data
  • 6. 5© 2019, LogMeIn, Inc. Database management system The database management system (DBMS) is the software that interacts with end users, applications, and the database itself to capture and analyze the data.
  • 7. 6© 2019, LogMeIn, Inc. Relational database system • A relational database management system (RDBMS) is a database management system (DBMS) based on the relational model of data. • The relational model (RM) for database management is an approach to managing data using a structure and language consistent with first-order predicate logic, first described in 1969 by English computer scientist Edgar F. Codd where all data is represented in terms of tuples, grouped into relations.
  • 8. 7© 2019, LogMeIn, Inc. RDBMS Id Title Author Year ISBN10 1 Omerta Mario Puzo 2000 0-434-00870-2 2 The Godfather Mario Puzo 1969 0-399-10342-2 3 Birdy William Wharton 1979 0-679-73412-0 4 Slaughterhouse- five Kurt Vonnegut 1969 0-7910-9295-X Id Name Year 1 Zoltan Kovacs 1998 2 Maria Vas 2000 3 Lajos Jo 2014 4 Klara Kis 1979
  • 9. 8© 2019, LogMeIn, Inc. Relational Database Management Systems • MySQL • PostgreSQL • SQLServer • Oracle RDBMS • DB2 • Amazon Aurora
  • 10. 9© 2019, LogMeIn, Inc. RDBMS’s (Pro) • SQL is a powerful query language • There’s a lot’s of relational databases available, with good support • It’s easy to find a developer with SQL experience • They’re ACID complaint – Atomicity – Consistency – Isolation – Durabilty
  • 11. 10© 2019, LogMeIn, Inc. RDBMS (Con) • The data has to be stored in a structured way, planning needed • It’s hard to convert between database tables and real objects • It’s hard to optimize on scaling, they’re mostly vertically scalable
  • 12. 11© 2019, LogMeIn, Inc. Non-relational databases (NoSQL) Relational databases were never designed to cope with the scale and agility challenges that face modern applications – and aren't built to take advantage of cheap storage and processing power that's available today through the cloud. NoSQL tries to solve these problems.
  • 13. 12© 2019, LogMeIn, Inc. Key – Value store • Memcached • Redis • Amazon DynamoDB
  • 14. 13© 2019, LogMeIn, Inc. Wide column store • Apache Cassandra • Apache HBase
  • 15. 14© 2019, LogMeIn, Inc. Document Store • MongoDB • Couchbase
  • 16. 15© 2019, LogMeIn, Inc. Graphdb • Neo4j
  • 17. 16© 2019, LogMeIn, Inc. Searchengine • Elasticsearch • Splunk • Apache solr
  • 18. 17© 2019, LogMeIn, Inc. Time series data • RRDTool • Prometheus
  • 19. 18© 2019, LogMeIn, Inc. NoSQL Pros • Flexibile Scalability • Stores Massive Amounts of data • Database maintenance could be easier • Cheaper to implement
  • 20. 19© 2019, LogMeIn, Inc. (Cap Theorem) • The CAP theorem states that it is impossible for a distributed data store to simultaneously provide more than two out of the following three guarantees: – Consistency: Every read receives the most recent write or an error – Availability: Every request receives a (non-error) response – without the guarantee that it contains the most recent write – Partition tolerance: The system continues to operate despite an arbitrary number of messages being dropped (or delayed) by the network between nodes
  • 21. 20© 2019, LogMeIn, Inc. NoSQL Cons • They’re not mature • Harder to get support • Business Analytics and Business Intelligence could be harder to implement
  • 22. 21© 2019, LogMeIn, Inc. SQL SELECT b.title FROM friends f JOIN books b ON b.year = f.year WHERE f.name = ‘Klara Kis’ Id Title Author Year ISBN1 0 1 Omerta Mario Puzo 2000 0-434- 00870- 2 2 The Godfat her Mario Puzo 1969 0-399- 10342- 2 3 Birdy William Wharto n 1979 0-679- 73412- 0 4 Slaught erhous e-five Kurt Vonneg ut 1969 0- 7910- 9295-x Id Name Year 1 Zoltan Kovacs 1998 2 Maria Vas 2000 3 Lajos Jo 2014 4 Klara Kis 1979
  • 23. 22© 2019, LogMeIn, Inc. DDL - Data definition language • CREATE • ALTER • DROP • TRUNCATE
  • 24. 23© 2019, LogMeIn, Inc. DQL - Data query language • SELECT • FROM • WHERE • GROUP BY • ORDER BY • HAVING
  • 25. 24© 2019, LogMeIn, Inc. DML - Data Manipulation Language • INSERT • UPDATE • DELETE
  • 26. 25© 2019, LogMeIn, Inc. JOIN • A JOIN clause is used to combine rows from two or more tables, based on a related column between them.
  • 27. 26© 2019, LogMeIn, Inc. INNER JOIN SELECT * FROM friends f JOIN books b +------+---------------+------+------+------------------+-----------------+------+---------------+ | id | Name | Year | id | Title | Author | Year | ISBN10 | +------+---------------+------+------+------------------+-----------------+------+---------------+ | 1 | Kovacs Zoltan | 1998 | 1 | Omerta | Mario Puzo | 2000 | 0-434-00870-2 | | 2 | Vas Maria | 2000 | 1 | Omerta | Mario Puzo | 2000 | 0-434-00870-2 | | 3 | Jo Lajos | 2014 | 1 | Omerta | Mario Puzo | 2000 | 0-434-00870-2 | | 4 | Kis Klara | 1979 | 1 | Omerta | Mario Puzo | 2000 | 0-434-00870-2 | | 1 | Kovacs Zoltan | 1998 | 2 | The Godfather | Mario Puzo | 1969 | 0-399-10342-2 | | 2 | Vas Maria | 2000 | 2 | The Godfather | Mario Puzo | 1969 | 0-399-10342-2 | | 3 | Jo Lajos | 2014 | 2 | The Godfather | Mario Puzo | 1969 | 0-399-10342-2 | | 4 | Kis Klara | 1979 | 2 | The Godfather | Mario Puzo | 1969 | 0-399-10342-2 | | 1 | Kovacs Zoltan | 1998 | 3 | Birdy | William Wharton | 1979 | 0-679-73412-0 | | 2 | Vas Maria | 2000 | 3 | Birdy | William Wharton | 1979 | 0-679-73412-0 | | 3 | Jo Lajos | 2014 | 3 | Birdy | William Wharton | 1979 | 0-679-73412-0 | | 4 | Kis Klara | 1979 | 3 | Birdy | William Wharton | 1979 | 0-679-73412-0 | | 1 | Kovacs Zoltan | 1998 | 4 | Slaughterhouse-5 | Kurt Vonnegut | 1969 | 0-7910-9295-x | | 2 | Vas Maria | 2000 | 4 | Slaughterhouse-5 | Kurt Vonnegut | 1969 | 0-7910-9295-x | | 3 | Jo Lajos | 2014 | 4 | Slaughterhouse-5 | Kurt Vonnegut | 1969 | 0-7910-9295-x | | 4 | Kis Klara | 1979 | 4 | Slaughterhouse-5 | Kurt Vonnegut | 1969 | 0-7910-9295-x | +------+---------------+------+------+------------------+-----------------+------+---------------+
  • 28. 27© 2019, LogMeIn, Inc. LEFT (OUTER) JOIN mysql> SELECT * FROM friends f LEFT JOIN books b ON b.Year = f.year +------+---------------+------+------+--------+-----------------+------+---------------+ | id | Name | Year | id | Title | Author | Year | ISBN10 | +------+---------------+------+------+--------+-----------------+------+---------------+ | 2 | Vas Maria | 2000 | 1 | Omerta | Mario Puzo | 2000 | 0-434-00870-2 | | 4 | Kis Klara | 1979 | 3 | Birdy | William Wharton | 1979 | 0-679-73412-0 | | 1 | Kovacs Zoltan | 1998 | NULL | NULL | NULL | NULL | NULL | | 3 | Jo Lajos | 2014 | NULL | NULL | NULL | NULL | NULL | +------+---------------+------+------+--------+-----------------+------+---------------+
  • 29. 28© 2019, LogMeIn, Inc. RIGHT (OUTER) JOIN mysql> SELECT * FROM friends f RIGHT JOIN books b ON b.year = f.year +------+-----------+------+------+------------------+-----------------+------+---------------+ | id | Name | Year | id | Title | Author | Year | ISBN10. | +------+-----------+------+------+------------------+-----------------+------+---------------+ | 2 | Vas Maria | 2000 | 1 | Omerta | Mario Puzo | 2000 | 0-434-00870-2 | | 4 | Kis Klara | 1979 | 3 | Birdy | William Wharton | 1979 | 0-679-73412-0 | | NULL | NULL | NULL | 2 | The Godfather | Mario Puzo | 1969 | 0-399-10342-2 | | NULL | NULL | NULL | 4 | Slaughterhouse-5 | Kurt Vonnegut | 1969 | 0-7910-9295-x | +------+-----------+------+------+------------------+-----------------+------+---------------+
  • 30. 29© 2019, LogMeIn, Inc. SELF JOIN mysql> SELECT * FROM friends a JOIN friends b; +------+---------------+------+------+---------------+------+ | id | Name | Year | id | Name | Year | +------+---------------+------+------+---------------+------+ | 1 | Kovacs Zoltan | 1998 | 1 | Kovacs Zoltan | 1998 | | 2 | Vas Maria | 2000 | 1 | Kovacs Zoltan | 1998 | | 3 | Jo Lajos | 2014 | 1 | Kovacs Zoltan | 1998 | | 4 | Kis Klara | 1979 | 1 | Kovacs Zoltan | 1998 | | 1 | Kovacs Zoltan | 1998 | 2 | Vas Maria. | 2000 | | 2 | Vas Maria | 2000 | 2 | Vas Maria | 2000 | | 3 | Jo Lajos | 2014 | 2 | Vas Maria | 2000 | | 4 | Kis Klara | 1979 | 2 | Vas Maria | 2000 | | 1 | Kovacs Zoltan | 1998 | 3 | Jo Lajos | 2014 | | 2 | Vas Maria | 2000 | 3 | Jo Lajos | 2014 | | 3 | Jo Lajos | 2014 | 3 | Jo Lajos | 2014 | | 4 | Kis Klara | 1979 | 3 | Jo Lajos | 2014 | | 1 | Kovacs Zoltan | 1998 | 4 | Kis Klara. | 1979 | | 2 | Vas Maria | 2000 | 4 | Kis Klara | 1979 | | 3 | Jo Lajos | 2014 | 4 | Kis Klara | 1979 | | 4 | Kis Klara | 1979 | 4 | Kis Klara | 1979 | +------+---------------+------+------+---------------+------+
  • 31. 30© 2019, LogMeIn, Inc. Indexes mysql> SHOW CREATE TABLE neos_largeG *************************** 1. row *************************** Table: neos_large Create Table: CREATE TABLE `neos_large` ( `id` int(11) DEFAULT NULL, [...] `ink` double DEFAULT NULL, `om` double DEFAULT NULL, `w` double DEFAULT NULL, KEY `tau` (`tau`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 1 row in set (0.00 sec) mysql> SELECT COUNT(*) FROM neos_large; +----------+ | COUNT(*) | +----------+ | 18254688 | +----------+ 1 row in set (4.04 sec)
  • 32. 31© 2019, LogMeIn, Inc. Indexes mysql> SELECT MAX(ink) FROM neos_large; +-------------------+ | MAX(ink) | +-------------------+ | 154.3668580789491 | +-------------------+ 1 row in set (5.10 sec) mysql> ALTER TABLE neos_large ADD INDEX(ink); Query OK, 0 rows affected (44.76 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> SELECT MAX(ink) FROM neos_large; +-------------------+ | MAX(ink) | +-------------------+ | 154.3668580789491 | +-------------------+ 1 row in set (0.00 sec)
  • 33. 32© 2019, LogMeIn, Inc. Views mysql> CREATE VIEW neos_ink AS SELECT id, ink FROM neos_large; Query OK, 0 rows affected (0.00 sec) mysql> SELECT * FROM neos_ink LIMIT 5; +----+---------------------+ | id | ink | +----+---------------------+ | 1 | 10.82856921420592 | | 2 | 11.56484503237207 | | 3 | 9.384537356044309 | | 4 | 26.68761210417409 | | 5 | 11.87652956555689 | +----+---------------------+ 5 rows in set (0.00 sec)
  • 34. 33© 2019, LogMeIn, Inc. Stored procedures DELIMITER $$ DROP PROCEDURE IF EXISTS duplicate_rows$$ CREATE PROCEDURE duplicate_rows ( IN tablename VARCHAR(255), IN times INT ) BEGIN SET @statement = CONCAT(CONCAT(CONCAT(CONCAT("INSERT INTO ",tablename)," SELECT * FROM "),tablename),";"); PREPARE stmt FROM @statement; WHILE times > 0 DO SELECT times as "Remaining"; EXECUTE stmt; SET times = times - 1; END WHILE; DEALLOCATE PREPARE stmt; END $$
  • 35. 34© 2019, LogMeIn, Inc. Functions CREATE FUNCTION circle_area (radius REAL) RETURNS REAL DETERMINISTIC RETURN POW(radius,2) * PI(); CREATE FUNCTION circle_circumference (radius REAL) RETURNS REAL DETERMINISTIC RETURN radius * 2 * PI();
  • 36. 35© 2019, LogMeIn, Inc. Triggers DELIMITER $$ CREATE TRIGGER remove_credit_card BEFORE INSERT ON users FOR EACH ROW BEGIN IF new.credit_card_number = '' THEN SET credit_card_number = NULL; END IF; END $$
  • 37. 36© 2019, LogMeIn, Inc. MongoDB “MongoDB is a document database with the scalability and flexibility that you want with the querying and indexing that you need”
  • 38. 37© 2019, LogMeIn, Inc. INSERT db.konyvek.insert( [ { Cim: "Omerta", Szerzo: "Mario Puzo", Ev: 2000, ISBN10: "0-434-00870-2"}, { Cim: "The Godfather", Szerzo: "Mario Puzo", Ev: 1969, ISBN10: "0-399-10342-2"}, { Cim: "Birdy", Szerzo: "William Wharton", Ev: 1979, ISBN10: "0-679-73412-0"}, { Cim: "Slaughterhouse-five", Szerzo: "Kurt Vonnegut ", Ev: 2000, ISBN10: "0-7910-9295-x"} ] )
  • 39. 38© 2019, LogMeIn, Inc. Find > db.konyvek.find( {Cim: "Slaughterhouse-five"} ) { "_id" : ObjectId("5c927003d9e410e1bb9fa583"), "Cim" : "Slaughterhouse-five", "Szerzo" : "Kurt Vonnegut ", "Ev" : 2000, "ISBN10" : "0-7910-9295-x" }
  • 40. 39© 2019, LogMeIn, Inc. Update > db.konyvek.update( {ISBN10: "0-7910-9295-x"}, {Cim: "Slaughterhouse-five", Szerzo: "Kurt Vonnegut ", Ev: 2000, ISBN10: "0-7910-9295-X"} ) WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
  • 41. 40© 2019, LogMeIn, Inc. “Schemaless” > db.konyvek.update({"Cim" : "Slaughterhouse-five", "Szerzo" : "Kurt Vonnegut ", "Ev" : 1969, "ISBN10" : "0-7910-9295-x"},{"Cim" : "Slaughterhouse-five", "Szerzo" : "Kurt Vonnegut ", "Ev" : 2000, "ISBN10" : "0-7910-9295-X", ISBN13: "978-0-7910- 9295-8"}) WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) > db.konyvek.find() { "_id" : ObjectId("5c929445345a87cb9fea0bc1"), "Cim" : "Omerta", "Szerzo" : "Mario Puzo", "Ev" : 2000, "ISBN10" : "0-434-00870-2" } { "_id" : ObjectId("5c929445345a87cb9fea0bc2"), "Cim" : "The Godfather", "Szerzo" : "Mario Puzo", "Ev" : 1969, "ISBN10" : "0-399-10342-2" } { "_id" : ObjectId("5c929445345a87cb9fea0bc3"), "Cim" : "Birdy", "Szerzo" : "William Wharton", "Ev" : 1979, "ISBN10" : "0-679-73412-0" } { "_id" : ObjectId("5c929445345a87cb9fea0bc4"), "Cim" : "Slaughterhouse-five", "Szerzo" : "Kurt Vonnegut ", "Ev" : 1969, "ISBN10" : "0-7910-9295-X", "ISBN13" : "978-0-7910-9295-8" }