0% found this document useful (0 votes)
15 views25 pages

tài liệu SQL

The document discusses SQL for testers including topics like database management systems, database relationships, SQL basics and advanced concepts, joins, functions, stored procedures, NoSQL, and references. It provides examples and explanations of key SQL concepts.

Uploaded by

ahnnguyen1106
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views25 pages

tài liệu SQL

The document discusses SQL for testers including topics like database management systems, database relationships, SQL basics and advanced concepts, joins, functions, stored procedures, NoSQL, and references. It provides examples and explanations of key SQL concepts.

Uploaded by

ahnnguyen1106
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

SQL for Testers

Fresher Tester
SQL for Testers
1. Database Management System – DBMS
2. Database Relationships
3. Install MS SQL Server 2012
4. SQL Basic
5. SQL Advanced
6. SQL Joins
7. SQL Functions
8. SQL Stored Procedures
9. SQL vs NoSQL
10. SQL Quiz
11. SQL CheetSheet
12. References
SQL for Testers
1. Database Management System – DBMS
2. Database Relationships
3. Install MS SQL Server 2012
4. SQL Basic
5. SQL Advanced
6. SQL Joins
7. SQL Functions
8. SQL Stored Procedures
9. SQL vs NoSQL
10. SQL Quiz
11. SQL CheetSheet
12. References
What is Database Management System – DBMS?

A database management system


(DBMS) refers to the technology for
creating and managing databases.

Basically, DBMS is a software tool to


organize (create, retrieve, update and
manage) data in a database.

The main aim of a DBMS is to supply a way to store up and retrieve database information that is both
convenient and efficient.
Database vs Data

In a database, even a smallest portion of information becomes the data.

Example:
Student is a data, address is a data, height, weight, marks everything is data.
In brief, all the living and non-living objects in this world is a data.

Student
Database in 3-tier Applications
A 3-tier application is an application program that is structured into three major parts; each of them
is distributed to a different place or places in a network.

The workstation or presentation layer

The business or application logic layer

The database and programming related


to managing layer
What is Transaction?
What is Transaction?

Transaction is an action, or series of actions that are being performed to read or update
the contents of the database.

A transaction can be defined as a logical unit of work on the database.


This may be an entire program, a piece of a program or a single command
(ex. INSERT or UPDATE) and it may engage in any number of operations on the database.
Example of a Transaction

UI Layer
Example of a Transaction

A simple example of a transaction will be dealing with the bank accounts of UserA and UserB.

This very simple and small transaction includes several steps:

Decrease UserA’s bank account from $500: Adding amount $500 in UserB’s account:
1. Open_Acc(UserA) 6. Open_Acc (UserB)
2. OldBal = UserA.bal 7. Old_Bal = UserB.bal
3. NewBal = OldBal – 500 //decrease 8. NewBal = OldBal + 500 //adding
4. Save_Acc(NewBal) 9. Save_Acc(NewBal)
5. Close_Acc (UserA) 10. Close_Acc(UserB)

Application Layer
Example of a Transaction

Database Layer
Properties of Transaction?
There are properties that all transactions should follow and possess. The four basic are in
combination termed as ACID properties. The ACID has a full form and is as follows:

ACID properties and its concepts of a transaction are put forwarded by


Haerder and Reuter in the year 1983.
Properties of Transaction?
There are properties that all transactions should follow and possess. The four basic are in combination
termed as ACID properties. The ACID has a full form and is as follows:

Atomicity: The ‘all or nothing’ property. A transaction is an indivisible entity that is either performed in its entirety
or will not get performed at all. This is the responsibility or duty of the recovery subsystem of the DBMS to ensure
atomicity.

Consistency: A transaction must alter the database from one steady state to another steady state. This is the
responsibility of both the DBMS and the application developers to make certain consistency. The DBMS can
ensure consistency by putting into effect all the constraints that have been particular on the database schema
such as integrity and enterprise constraints.

Isolation: Transactions that are executing independently of one another is the primary concept followed by
isolation. In other words, the fractional effects of incomplete transactions should not be visible or come into notice
to other transactions going on simultaneously. It is the responsibility of the concurrency control sub-system to
ensure adapting the isolation.

Durability: The effects of a successfully accomplished transaction are permanently recorded in the database
and must not get lost or vanished due of a subsequent failure. So this becomes the responsibility of the recovery
sub-system to ensure durability.
Distributed DBMS

Distributed Database: A logically interconnected set of shared data (and a description of this data)
physically scattered over a computer network.

This software system allows the


management of the distributed database and makes
the distribution transparent to users.

A Distributed Database Management System (DDBMS)


contains a single logical database that is divided into a
number of fragments.
Applications of Replication

Some applications are sufficiently


supported with only partial
synchronization between the
copies of the database and the
corporate database system; while
many other applications insist
continuous synchronization
between all copies of the
database.
Recap
Database vs Data
In a database, even a smallest portion of information
DBMS becomes the data.

Transaction
applications users An action, or series of actions that are being
performed to read or update the contents of the
database.

Database ACID properties


applications users Atomicity | Consistency |Isolation | Durability

Distributed DBMS
A logically interconnected set of shared data (and a
description of this data) physically scattered over a
users computer network.
applications
Database Replication
Some well-known DBMSs Changes done at one site are captured and stored
Microsoft SQL Server, Oracle, locally before being forwarded and applied at each
MySQL, PostgreSQL, MongoDB, MariaDB, of database’s remote locations.
Sybase, SAP HANA, and IBM DB2
SQL for Testers
1. Database Management System – DDMS
2. Database Relationships
3. Install MS SQL Server 2012
4. SQL Basic
5. SQL Advanced
6. SQL Joins
7. SQL Functions
8. SQL Stored Procedures
9. SQL vs NoSQL
10. SQL Quiz
11. SQL CheetSheet
12. References
DB Relationship Sample
DB Relationships – 1:1

101 301
CUSTOMER ADDRESS

102 302
CUSTOMER ADDRESS
DB Relationships – 1:n
101 555
CUSTOMER ORDER

ORDER
557

102 556
CUSTOMER ORDER
DB Relationships – n:n

555 555 201 201


ORDER ITEM_ORDER ITEM

555
202 202
ITEM_ORDER ITEM
556

203 203
ORDER ITEM_ORDER ITEM
556 556
Examples
Primary and Foreign Key Constraints
Primary keys and foreign keys are two types of constraints that can be used to enforce data integrity
in SQL Server tables. These are important database objects.

parent table
primary keys (referenced table) foreign keys

PersonID LastName FirstName Age OrderID OrderNumber PersonID


1 Hansen Ola 30
1 77895 3
2 Svendson Tove 23
2 44678 3
3 Pettersen Kari 20
3 22456 2
"Persons" table
4 24562 1
"Orders" table
child table

A foreign key is a key used to


link two tables together.
Recap
DB Relationship Types

primary keys
foreign keys

parent table
(referenced table)

Col1 Col2 Col3 Col4 Col1 Col2 Col3

1 ### ### # 1 ### #

2 ### ### # 2 ### #

3 ### ### # 3 ### #

4 ### #

child table
A foreign key is a key used to
link two tables together.

You might also like