Development course SQL databases in node

Содержание

Слайд 2

1 CONFIDENTIAL Agenda of the lecture • Important Aspects of Relational

1

CONFIDENTIAL

Agenda of the lecture

• Important Aspects of Relational Databases;
• Create Relationships

among Tables;
• SQL COMMANDS;
- DDL - Data Definition Language
- DML - Data Manipulation Language
- DCL - Data Control Language
- TCL - Transaction Control Language
- Transaction Isolation Levels
• Native node - postgresql driver
- Connection
- Queries
- Pool, TCL
TODO
Слайд 3

1 CONFIDENTIAL DATABASES SQL PL/pgSQL SQL SQL PL/SQL SQL TSQL

1

CONFIDENTIAL

DATABASES

SQL PL/pgSQL

SQL

SQL PL/SQL

SQL TSQL

Слайд 4

1 CONFIDENTIAL Important Aspects of Relational Databases

1

CONFIDENTIAL

Important Aspects of Relational Databases

Слайд 5

1 CONFIDENTIAL Create Relationships among Tables One-to-One (1:1) One-to-Many (1:N) Many-to-Many

1

CONFIDENTIAL

Create Relationships among Tables

One-to-One (1:1)

One-to-Many (1:N)

Many-to-Many (N:М)

PK

PK

PK

PK

PK

FK

FK

FK

FK

PK - Primary Key

FK -

Foreign Key
Слайд 6

1 SQL Commands CONFIDENTIAL

1

SQL Commands

CONFIDENTIAL

Слайд 7

1 DDL- Data Definition Language CONFIDENTIAL Data Definition Language is used

1

DDL- Data Definition Language

CONFIDENTIAL

Data Definition Language is used to define the

database structure or schema. DDL is also used to specify additional properties of the data.
CREATE (DATABASE, TABLE, VIEW, TRIGGER, PROCEDURE) : to create objects in database
ALTER (DATABASE, TABLE, VIEW, TRIGGER, PROCEDURE) : alters the structure of database
DROP (DATABASE, TABLE, VIEW, TRIGGER, PROCEDURE) : delete objects from database
RENAME (DATABASE, TABLE, VIEW, TRIGGER, PROCEDURE) : rename an objects
TRUNCATE TABLE : The result of this operation quickly removes all data from a table, typically bypassing a number of integrity enforcing mechanisms.
Слайд 8

1 CONFIDENTIAL DML-Data Manipulation Language DML statements are used for managing

1

CONFIDENTIAL

DML-Data Manipulation Language

DML statements are used for managing data within schema

objects.
DML are of two types:
Procedural DMLs : require a user to specify what data are needed and how to get those data.
Declarative DMLs : (also referred as Non-procedural DMLs) : require a user to specify what data are needed without specifying how to get those data.
Declarative DMLs are usually easier to learn and use than procedural DMLs. However, since a user does not have to specify how to get the data, the database system has to figure out an efficient means of accessing data.
SELECT: retrieve data from the database
INSERT: insert data into a table
UPDATE: update existing data within a table
DELETE: deletes all records from a table, space for the records remain
Слайд 9

1 DDL AND SIMPLE DML EXAMPLES CONFIDENTIAL

1

DDL AND SIMPLE DML EXAMPLES

CONFIDENTIAL

Слайд 10

1 CONFIDENTIAL 1 2 3 4

1

CONFIDENTIAL

1

2

3

4

Слайд 11

1 CONFIDENTIAL 5 6 7 8 9 10

1

CONFIDENTIAL

5

6

7

8

9

10

Слайд 12

1 CONFIDENTIAL 13 11 12 14 15

1

CONFIDENTIAL

13

11

12

14

15

Слайд 13

1 DML QUERY EXAMPLES CONFIDENTIAL

1

DML QUERY EXAMPLES

CONFIDENTIAL

Слайд 14

1 CONFIDENTIAL 1 2 3 4

1

CONFIDENTIAL

1

2

3

4

Слайд 15

1 CONFIDENTIAL 5 6 7 8 9 10

1

CONFIDENTIAL

5

6

7

8

9

10

Слайд 16

1 CONFIDENTIAL 11 12 13 14

1

CONFIDENTIAL

11

12

13

14

Слайд 17

1 DML QUERY WITH INDEX EXAMPLES CONFIDENTIAL

1

DML QUERY WITH INDEX EXAMPLES

CONFIDENTIAL

Слайд 18

1 2 3 1 CONFIDENTIAL 14 4 5 6 7 8

1

2

3

1

CONFIDENTIAL

14

4

5

6

7

8

Слайд 19

1 CONFIDENTIAL SQL Joins

1

CONFIDENTIAL

SQL Joins

Слайд 20

1 DML QUERY JOINS EXAMPLES CONFIDENTIAL

1

DML QUERY JOINS EXAMPLES

CONFIDENTIAL

Слайд 21

1 CONFIDENTIAL 1 2 3 4 5 6

1

CONFIDENTIAL

1

2

3

4

5

6

Слайд 22

1 CONFIDENTIAL 8 7 9

1

CONFIDENTIAL

8

7

9

Слайд 23

1 CONFIDENTIAL 10 11

1

CONFIDENTIAL

10

11

Слайд 24

1 CONFIDENTIAL DCL- Data Control Language A Data Control Language is

1

CONFIDENTIAL

DCL- Data Control Language

A Data Control Language is a syntax similar

to a computer programming language used to control access to data stored in a database (Authorization). In particular, it is a component of Structured Query Language (SQL).
Examples of DCL commands :
GRANT: allow specified users to perform specified tasks.
REVOKE: cancel previously granted or denied permissions.
The operations for which privileges may be granted to or revoked from a user or role apply to both the Data definition language (DDL) and the Data manipulation language (DML), and may include CONNECT, SELECT, INSERT, UPDATE, DELETE, EXECUTE and USAGE.
Слайд 25

1 CONFIDENTIAL TCL- Transaction Control Language Transaction Control Language commands are

1

CONFIDENTIAL

TCL- Transaction Control Language

Transaction Control Language commands are used to manage

transactions in the database. These are used to manage the changes made by DML-statements. It also allows statements to be grouped together into logical transactions.
Examples of TCL commands:
COMMIT: Commit command is used to permanently save any transaction
into the database.
ROLLBACK: This command restores the database to last committed state.
It is also used with savepoint command to jump to a savepoint
in a transaction.
SAVEPOINT: Savepoint command is used to temporarily save a transaction so
that you can rollback to that point whenever necessary.
Слайд 26

1 CONFIDENTIAL Transaction isolation levels vs read phenomena

1

CONFIDENTIAL

Transaction isolation levels vs read phenomena

Слайд 27

1 CONFIDENTIAL Lost Update Dirty Read Non-Repeatable-Read Phantom Reads

1

CONFIDENTIAL

Lost Update

Dirty Read

Non-Repeatable-Read

Phantom Reads

Слайд 28

1 CONFIDENTIAL Serialization Anomalies XA - Transaction

1

CONFIDENTIAL

Serialization Anomalies

XA - Transaction

Слайд 29

1 TCL DEMO EXAMPLES CONFIDENTIAL

1

TCL DEMO EXAMPLES

CONFIDENTIAL

Слайд 30

1 1 CONFIDENTIAL 2 3 4 5

1

1

CONFIDENTIAL

2

3

4

5

Слайд 31

1 CONFIDENTIAL Native node - postgresql driver (Connection) Link Nodejs driver

1

CONFIDENTIAL

Native node - postgresql driver (Connection)

Link Nodejs driver api: https://node-postgres.com
Free Database(
20MB

data, 5concurrent connections
):
https://www.elephantsql.com/
Слайд 32

1 CONFIDENTIAL Native node - postgresql driver (Queries)

1

CONFIDENTIAL

Native node - postgresql driver (Queries)