Professional Documents
Culture Documents
7th Jan 2023 - Database Testing - Mangesh Sir
7th Jan 2023 - Database Testing - Mangesh Sir
VCTC,Katraj,Pune
- Validating all front end operations are stored in the database or not
- Front end operation / data entered in the front end is stored in the data base or not
- We check data can be fetched or not
- For data fetch purpose there to be use SQL language
- There are different commands of SQL & by using that we can fetch data
Ex.
Project – Kite
Register page
Syntax
Example
Output
DATA:-
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
Piece of information
Roll No
Student FN Data
LN
Employee ID
Project
Object/Entity
Information:-
Eg. VCTC- 7th Jan 2023 Morning Batch Katraj- Processed Data
1. Structured data
2. Un-structured data
Structure data:-
Data which is arranged in a structured manner or structured way it is nothing but structured
data
Rows/Records/Tuples
Examples of structured data include names, dates, addresses, credit card numbers, stock
information, and more. Structured data is highly organized and easily understood by machine
language.
Un-structured data:-
Examples of unstructured data has many faces like text files, PDF documents, social media
posts, comments, images, audio/video files, and emails, to name a few.
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
What is a Database?
3. It is an electronic system that makes data access, data manipulation, data retrieval,
data storing, and data management very easy.
4. Almost every organization uses the database for storing the data due to its easily
accessible and high operational case.
5. The database provides perfect access to data and lets us perform required tasks.
o Software
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
o Data
o Procedures
o Database Languages
o Query Processor
o Database Manager
o Database Engine
o Reporting
The database management systems can be categorized into several types. Some of the
important lists are given below:
What is RDBMS?
3. RDBMS stores the data into the collection of tables and links those tables using the
relational operators easily whenever required.
2. Hierarchical database
Here data will be stored in the form of parent – child relation or in a tree structure
Advantage- Data duplication not allowed
Disadvantages- retrieval time consuming
An example of a hierarchical database is given below –
3. Network database
Here data will be stored in a network structure. All the nodes (data) are interlinked with
another data
Here data will be stored in the form of rows & columns i.e. in a table structure
A relational database management system (RDBMS) is a system where data is
organized in two-dimensional tables using rows and columns.
This is one of the most popular data models which is used in industries. It is based on
SQL.
Every table in a database has a key field which uniquely identifies each record.
This type of system is the most widely used DBMS.
Data Integrity
It is used to get accuracy, correctness & consistency of the column of the table & it can be
achieved by data types & constraints (rules & regulation- apply on column)
Constraints-
-------------------------------------------------------------------------------------------------------------------
SQL
1. SQL (Structured Query Language) is used to perform operations on the records stored
in the database such as updating records, deleting records, creating and modifying
tables, views, etc.
2. SQL is just a query language; it is not a database. To perform SQL queries, you need to
install any database, for example, Oracle, MySQL, MongoDB, PostGre SQL, SQL Server,
DB2, etc.
What is SQL?
4. SQL is a database language, it is used for database creation, deletion, fetching rows,
and modifying rows, etc.
All DBMS like MySQL, Oracle, MS Access, Sybase, Informix, PostgreSQL, and SQL
Server use SQL as standard database language.
SQL is required:
o With SQL, we can query our database in several ways, using English-like statements.
o With SQL, a user can access data from a relational database management system.
o It allows the user to define the data in the database and manipulate it when needed.
SQL Syntax
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
SQL follows some unique set of rules and guidelines called syntax. Here, we are providing all
the basic SQL syntax.
o SQL is not case sensitive. Generally SQL keywords are written in uppercase.
o SQL statements are dependent on text lines. We can place a single SQL statement on
one or multiple text lines.
o You can perform most of the action in a database with SQL statements.
SQL statement
SQL statements are started with any of the SQL commands/keywords like SELECT, INSERT,
UPDATE, DELETE, ALTER, DROP etc. and the statement ends with a semicolon (;).
Semicolon is used to separate SQL statements. It is a standard way to separate SQL statements
in a database system in which more than one SQL statements are used in the same call.
SQL Commands
SQL Commands
o SQL commands are instructions. It is used to communicate with the database. It is also
used to perform specific tasks, functions, and queries of data.
o SQL can perform various tasks like create a table, add data to tables, drop the table,
modify the table, and set permission for users.
Types of SQL Commands / Types of SQL / Subtypes of SQL/ Subset of SQL commands
There are five types of SQL commands: DDL, DML, DCL, TCL, and DQL.
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
o DDL changes the structure of the table like creating a table, deleting a table, altering a
table, etc.
o All the command of DDL are auto-committed that means it permanently save all the
changes in the database.
o CREATE TABLE
o ALTER TABLE
o DROP TABLE
o TRUNCATE TABLE
o DML commands are used to modify the database. It is responsible for all form of
changes in the database.
o The command of DML is not auto-committed that means it can't permanently save all
the changes in the database. They can be rollback.
o INSERT
o UPDATE
o DELETE
o SELECT
o GRANT
o REVOKE
o COMMIT
o ROLLBACK
o SET TRANSACTION
o SAVEPOINT
Database -
A database contains one or more tables & each table identified by a name (eg. Signup, Register,
Login credentials, Employee info, Students info……etc.)
Example:-
ID-
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
FN-
LN-
MobNo-
EmailId-
City-
1. SELECT
- The SQL SELECT Statement is used to select data from a table / database
- Ex. Select all the records in the Sign Up table
A. Select all data from the table / Select all table information / fetch all table information /
retrieve all table information
Syntax
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
Example
Output
Syntax
FROM table_name;
Example
SELECT FN, LN
FROM SignUp;
Output -
FN LN
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
1 Rahul Gandhi
2 Arvind Kejriwal
3 Anna Hajare
4 Sharad Pawar
5 Soniya Gandhi
System generated column – Oracle
2. DISTINCT
- The SQL DISTINCT statements used to return / show only distinct value (Unique value /
different value (Duplicate value are not present)) in the particular column
- Inside a table, a column contains many duplicate values, & sometimes we wants to list
of the only unique value
- Ex. Select only the distinct value from the LN column in the SignUp table
Syntax
FROM table_name;
Example
SELECT DISTINCT LN
FROM SignUp;
Output
LN
1 Gandhi
2 Kejriwal
3 Hajare
4 Pawar
Without Distinct
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
Syntax
FROM table_name;
Example
SELECT LN
FROM SignUp;
Output
LN
1 Gandhi
2 Kejriwal
3 Hajare
4 Pawar
5 Gandhi
Syntax
Example
FROM SignUp;
Output
COUNT(DISTINC
T LN)
1 4
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
3. TOP/ ROWNUM/LIMIT
- It is SQL statement used to specify the number of record to return
- It is a SQL statements used to show/display/return the top records in a particular table
- It is SQL statements use to select top values/records in particular table
Syntax
Example
Output
Syntax
Example
Output
ROWNUM – Oracle
Syntax
WHERE ROWNUM<=value;
Example
WHERE ROWNUM<=3;
Output
LIMIT- MySQL
Syntax
LIMIT value;
Example
LIMIT 3;
Output
4. ORDER BY
- It is a SQL statements used to sort the result set in ascending order and descending order
- The ORDER BY keywords sorts the records in ascending order by default or use the ASC
keywords
- To sorts the records in descending order to use the DESC keywords
- It is used to display records by ascending order and descending order from selected
column
Ascending Descending
1 2 3 4 5 5 4 3 2 1
A B C D E E D C B A
1. Ascending order
Syntax
Example
Output
2. Descending order
Syntax
SELECT * FROM table name
ORDER BY Column name DESC;
Example
SELECT * FROM SignUp
ORDER BY FN DESC;
Output
5. WHERE clause
- The WHERE clause used to filter out the records
- It is used to extract only those records that full filled a specified condition
Syntax
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
WHERE Condition;
Example
Output
Example
WHERE ID = 1;
Output
Syntax
WHERE condition;
Example
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
SELECT Email Id
FROM SignUp
WHERE City=’Pune’;
Output
Email Id
1 1@gmail.com
2 3@gmail.com
3 5@gmail.com
Different Operators
1. OR
2. AND
3. LIKE
4. WILDCARD
5. NOT
6. IN
7. BETWEEN
OR
- it is a SQL statements use to select records when both condition is true or one condition
is true
- it is a SQL statements use to select records either one condition must be true then output
is true
1 1 = 1
1 0 = 1
0 1 = 1
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
0 0 = 0
Syntax
Example
Output
Syntax
Example
SELECT Email Id
FROM SignUp
Output
Email Id
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
1 1@gmail.com
2 5@gmail.com
AND
- it is a SQL statements in that select records when both the conditions must be true then
output will be true
1 1 = 1
0 1 = 0
1 0 = 0
0 0 = 0
Syntax
Example
Output
Syntax
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
Example
SELECT Mob.No
FROM SignUp
Output
Mob. No
1 1111
LIKE
Mangesh _ang___ =
- The like operator is used in WHERE clause to search a specified pattern in a column
- In like operator use % sign / symbol
a. For starting with specified alphabets
Syntax
Example
Output
Syntax
Example
SELECT LN
FROM SignUp
Output
LN
1 Kejriwal
2 Hajare
Mangesh -----------------------------h
Syntax
Example
Output
Syntax
Example
SELECT LN
FROM SignUp
Output
LN
1 Kejriwal
2 Pawar
NOT
Syntax
Example
Output
Ex.
Arvind = A%d
Ex.
Arvind = %vin%
Select all records where the value of the column starts with the letter "A".
Syntax
Select all records where the value of the column ends with the letter "a".
Syntax
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
Select all records where the value of the column starts with letter "A" and ends with the letter
"b".
Syntax
Select all records where the value of the column contains the letter "a".
Syntax
Select all records where the value of the column does NOT start with the letter "A".
Syntax
The following SQL statement selects all Sign Up with a FN starting with "A", "B", or "C":
Syntax
The following SQL statement selects all Sign Up with a FN ending with "A", "B", or "C":
Syntax
WHERE Column LIKE 'a%' Finds any values that start with "a"
WHERE Column LIKE '%or%' Finds any values that have "or" in any
position
WHERE Column LIKE '_r%' Finds any values that have "r" in the second
position
WHERE Column LIKE 'a_%' Finds any values that start with "a" and are
at least 2 characters in length
WHERE Column LIKE 'a__%' Finds any values that start with "a" and are
at least 3 characters in length
WHERE Column LIKE 'a%o' Finds any values that start with "a" and ends
with "o"
WILDCARD
Ex.
Mangesh
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
Syntax
Example
Output
Rahul
Aahul
IN
Syntax
Example
WHERE FN IN (‘Rahul’,’Soniya’);
Output
NOT
Syntax
Example
Output
Examples
WHERE ID IN (1,4,5);
Output
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
Examples
Output
BETWEEN
Syntax
Example
Output
Example
Output
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
Example
To display the products outside the range of the previous example, use NOT BETWEEN:
Syntax
Example
Output
DISTINCT
TOP
ORDER BY
WHERE CLAUSE
Operators
1. OR
2. AND
3. LIKE
4. WILDCARD
5. NOT
6. IT
7. BETWEEN
INSERT INTO
UPDATE
DELETE
ALIAS
SELECT INTO
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
CREATE TABLE
DROP TABLE
TRUNCATE TABLE
ALTER TABLE
CONSTRAINTS
JOIN
AGGREGATE FUNCTION
GROUP BY
HAVING
INTERNVIEW QUESTIONS
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
INSERT INTO
Syntax
Example
Output
Syntax
INSERT INTO table name column name 1, column name 2, column 3…..
Example
Output
UPDATE
Syntax
WHERE condition;
Example
UPDATE SignUp
WHERE FN=’Rahul’;
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
Output
Note- Missing WHERE clause = all records in the table will be updated by given set value
Syntax
Example
UPDATE SignUp
Output
DELETE
Syntax
WHERE condition;
Example
WHERE Mob.No=2222;
Output
Note- Missing WHERE clause = All records in the table will be deleted – delete all records
Syntax
Example
Output
ALIAS
Ex.
- It is a SQL statements – used to change the temporary column name or table name
without changing in the database
First Name – FN
- Use AS keyword
- Adv- Column name are wide range or not readable properly
Syntax
Example
FROM SignUp;
Output
FN LN
Rahul Gandhi
Arvind Kejriwal
Anna Hajare
Sharad Pawar
Soniya Gandhi
Syntax
Example
Output
Table Name = SU
FN LN
Rahul Gandhi
Arvind Kejriwal
Anna Hajare
Sharad Pawar
Soniya Gandhi
SELECT INTO
- The SELECT into keyword is used to copies data from one table in to another table
Syntax
Example
Output
Table 2 – LN – 5 records
- In UNION is used to combine the result set of two or more select statements
- Condition
1. The column must have similar data type
2. Every select statement within union have the same no of column
3. The column in every select statements must have the same order
Example
Syntax
UNION
Example
UNION
Output
LN
1 Deshmukh
2 Gandhi
3 Hajare
4 Kejriwal
5 Pawar
6 Raut
7 Thakre
Syntax
UNION ALL
Example
UNION
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
Output
LN
1 Deshmukh
2 Gandhi
3 Gandhi
4 Gandhi
5 Gandhi
6 Hajare
7 Hajare
8 Kejriwal
9 Kejriwal
10 Pawar
11 Pawar
12 Pawar
13 Raut
14 Thakre
==================================================================
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
CREATE TABLE
Syntax
Nth
);
Example
ID int,
FN varchar(255),
LN varchar(255),
Mob.No int,
Email Id varchar(255),
City varchar(255)
);
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
Output
DROP TABLE
Syntax
Example
Output
TURNCATE TABLE
- The truncate table keywords is used to delete the data inside a table but not the table
itself
- It is used to delete all the rows / records from the table
- It is used to delete all stored records in the table but the structure remains same
- Not delete the structure of the table
Syntax
Example
Output
DROP
ALTER TABLE
- The alter table is used to add column, drop column, & modify column in an existing
table
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
Syntax
Example
Output
Syntax
Example
Output
Syntax
Syntax
Syntax
Example
MODIFY FN char(10);
Output
=======================================================================
Constraints
Syntax
Nth
);
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
- NULL
- NOT NULL
- UNIQUE KEY
- PRIMARY KEY
- FOREGIN KEY
- CHECK
- DEFAULT
Example
Example
);
Constraints Types-
NULL
NOT NULL
);
UNIQUE KEY
Example
FN varchar(255),
LN varchar(255),
City varchar(255),
Age int,
);
Primary Key
Note- When multiple filed are used a primary key, they are called a Composite key
ID int ,
FN varchar(255) ,
LN varchar(255) ,
Mob.No int ,
Email Id varchar(255) ,
City varchar(255) ,
Age int ,
);
Foreign KEY
Example
AADHAR NO int(25),
LASTNAME varchar(256),
CITY varchar(25),
FIRSTNAME varchar(256),
LASTNAME varchar(256),
Notice that the "AADHAR NO" column in the "ICICI", "AADHAR NO" column in the "IDBI"
table points to the "AADHAR NO" column in the "UIDAI" table.
The "AADHAR NO" column in the "UIDAI" table is the PRIMARY KEY in the "UIDAI" table.
The "AADHAR NO" column in the "ICICI" table is a FOREIGN KEY in the "ICICI" table.
The "AADHAR NO" column in the "IDBI" table is a FOREIGN KEY in the "IDBI" table.
Default
ID int ,
FN varchar(255) ,
LN varchar(255) ,
Mob.No int ,
Email Id varchar(255) ,
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
Age int ,
);
Check
ID int ,
FN varchar(255) ,
LN varchar(255) ,
Mob.No int ,
Email Id varchar(255) ,
City varchar(255) ,
);
What is constraints?
What is difference between unique key, primary key & foreign key?
Primary key cannot have a Foreign key can accept multiple Unique Constraint
NULL value. NULL value. may have a NULL
value.
Each table can have only We can have more than one foreign Each table can have
one primary key. key in a table. more than one
Unique Constraint.
=======================================================================
JOINS
- JOIN is used to join two or more table on primary key & foreign key
- JOIN is a SQL statements it is used to join two or more table based on the basic
relationship between primary key & foreign key
- The SQL joins is used to combine records from two or more tables in a database
- A JOIN means combining fields from two tables by using values common to each
1. INNER JOIN
2. LEFT JOIN
3. RIGHT JOIN
4. FULL JOIN
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
INNER JOIN
LEFT JOIN
- Return all records from the left table & the matching records from both table / right
table
RIGHT JOIN
- Return all records from the right table & the matching records from both table / left
table
FULL JOIN
Prepared By- Mangesh Sir
VCTC,Katraj,Pune
- Return all records from the left table & right table & the matching records from both
table
=======================================================================
Aggregate Functions
Group By
Having
Find Salary?