1. Introduction to SQL
SQL (Structured Query Language) is a standard language for managing and manipulating
databases. In software testing, SQL is crucial for validating data, retrieving test data, and
verifying database transactions. Testers frequently use SQL to ensure that the backend data
behaves as expected.
SQL is divided into various commands, including:
1. 1. DDL (Data Definition Language): Commands like CREATE, ALTER, DROP.
2. 2. DML (Data Manipulation Language): Commands like SELECT, INSERT, UPDATE,
DELETE.
3. 3. DCL (Data Control Language): Commands like GRANT, REVOKE.
4. 4. TCL (Transaction Control Language): Commands like COMMIT, ROLLBACK.
2. SQL Databases
A database is an organized collection of structured information or data, typically stored
electronically in a computer system. SQL databases are relational databases, where data is
stored in tables consisting of rows and columns.
Key concepts:
5. 1. Tables: A table is a collection of data organized in rows and columns.
6. 2. Records (Rows): Each row represents a record in the table.
7. 3. Fields (Columns): Each column represents an attribute of the data.
3. Basic SQL Commands
Some of the most common SQL commands include:
3.1 CREATE TABLE
The CREATE TABLE command is used to create a new table in a database.
Example:
CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
Department VARCHAR(50)
, );
3.2 INSERT INTO
The INSERT INTO command is used to insert new records into a table.
Example:
INSERT INTO Employees (EmployeeID, FirstName, LastName, Department)
VALUES (1, 'John', 'Doe', 'HR');
3.3 SELECT
The SELECT statement is used to select data from a database.
Example:
SELECT FirstName, LastName, Department
FROM Employees
WHERE Department = 'HR';
4. Data Types in SQL
SQL supports various data types, including:
8. 1. Numeric: INT, DECIMAL, FLOAT
9. 2. String: CHAR, VARCHAR, TEXT
10. 3. Date and Time: DATE, DATETIME, TIME
5. SQL Joins
SQL joins are used to combine rows from two or more tables, based on a related column
between them. Common types of joins include:
5.1 INNER JOIN
The INNER JOIN selects records that have matching values in both tables.
Example:
SELECT Employees.FirstName, Departments.DepartmentName
FROM Employees