Professional Documents
Culture Documents
1. B
2. I
3. E
4. D/B
5. S
6. C
Database Testing
FN- M
LN- C
Email- CM
Mb. No-12
Address-Pune
Submit
Database-
What is SQL-
SQL- used
- Database creation
- deletion
- Fetching row
- Modifying row
- To create database/table
- To insert record
- To update record
- To delete records
- To retrieve data
SQL Syntax
SQL follows some unique set of rules & regulation called syntax
SQL- is not case sensitive. Generally SQL keywords are written in Uppercase
SQL Statement
Delete-
Create table-
Alter table-
Drop table-
Inert in to –
SQL Commands- are instruction. It is used to communicate with the database also used to
perform specific task
- Changes the structure of the table like creating a table, delete a table, altering table etc….
- All DDL command- auto committed – means – it permanently save all the changes in the
database
- DDL commands
1. Create
2. Alter
3. Drop
4. Truncate
Database- collection of data- storage – no of table – row (records) & column (field)
Ex. Sign up, login credentials, orders, employee info, student’s registration
Table Name- Sign Up – front end- UI- ID,FN,LN,MObNo,EmailID, City- submit- successful
SELECT Syntax
Example
Output
Syntax
or
FROM tablename;
Example-
Or
SELECT FN, LN
FROM SignUP;
Output-
FN LN
1 Rahul Gandhi
2 Arvind Kejriwal
3 Anna Hajare
4 Sharad Pawar
5 Soniya Gandhi
2. Distinct
- Keyword / statement is used to return only distinct value/ different value/ unique value in
the particular column
- Table – column- many duplicate value – sometimes we want only unique value
- Ex. LN – distinct value select
Syntax
FROM tablename;
Example
Output
LN
1 Gandhi
2 Kejriwal
3 Hajare
4 Pawar
Count
Syntax
FROM tablename;
Example
Output
Number of records- 4
Without Distinct
Example
Output
LN
1 Gandhi
2 Kejriwal
3 Hajare
4 Pawar
5 Gandhi
Syntax
Example
Output
RONUM(Oracal)
Where RONUM<=value;
Where RONUM<=3;
Limit (MySql)
LIMIT value;
LIMIT 2;
Output
ORDER BY
Order by keyword – it used to sort the result set in ascending & descending order
It is used to display the records by ascending & descending order from selected column
Ascending order
ORDERBY FN;
Descending order
ORDERBY FN DESC;
WHERE condition;
WHERE City=Pune;
WHERE Columnane=value;
WHERE ID=1;
WHERE condition;
WHERE City=Pune;
Email Id
1 1@gmail.com
2 3@gmail.com
3 5@gmail.com
1. Or
2. And
Logic gates
OR- 1 1 =1 1 0 =1 0 1 =1 0 0 =0
AND- 1 1 =1 1 0 =0 0 1 =0 0 0 =0
OR-
Email Id
1 1@gmail.com
2 5@gmail.com
AND
- Select records when both the condition must be true the we get the output will be true
Mob. No
1 1111
Like Operator
End Name H
Like operator it is used in a where clause to search for a specified pattern in a column
1. % -----multiple characters
2. _ ------ single character
LN
1 Kejriwal
2 Hajare
LN
1 Kejriwal
2 Pawar
A%d
[ABC]%
%[ABC]
Select all records where the value of the column starts with the letter "A".
Syntax
SELECT * FROM table_name
WHERE column LIKE “A%”;
Select all records where the value of the column ends with the letter "a".
Syntax
SELECT * FROM table_name
WHERE column LIKE “%a”;
Select all records where the value of the column starts with letter "A" and ends with the
letter "b".
Syntax
SELECT * FROM table_name
WHERE column LIKE “A%b”;
Select all records where the value of the column contains the letter "a".
Syntax
SELECT * FROM table_name
WHERE column LIKE “%a%”;
Select all records where the value of the column does NOT start with the letter "A".
Syntax
SELECT * FROM table_name
WHERE column NOT LIKE “A%”;
The following SQL statement selects all Sign Up with a FN starting with "A", "B", or "C":
Syntax
SELECT * FROM table_name
WHERE column LIKE “[ABC]%”;
The following SQL statement selects all Sign Up with a FN ending with "A", "B", or "C":
Syntax
SELECT * FROM table_name
WHERE column LIKE “%[ABC]”;
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 3 characters in length
WHERE Column LIKE 'a%o' Finds any values that start with "a" and ends
with "o"