tài liệu SQL
tài liệu SQL
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?
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
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.
Transaction is an action, or series of actions that are being performed to read or update
the contents of the database.
UI Layer
Example of a Transaction
A simple example of a transaction will be dealing with the bank accounts of UserA and UserB.
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:
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.
Transaction
applications users An action, or series of actions that are being
performed to read or update the contents of the
database.
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
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
primary keys
foreign keys
parent table
(referenced table)
4 ### #
child table
A foreign key is a key used to
link two tables together.