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"
Wildcard operator
IN operator
- Used to fetch one or more data from the table
- It is use to select those records which specify in query
WHERE FN IN (‘Rahul’,’Soniya’);
NOT between
SELECT * FROM SignUp
INSERT INTO
UPDATE
UPDATE tablename
WHERE codition;
UPDATE SignUp
WHERE FN=Rahul;
UPDATE SignUp
Condition= Coumnname=value
Delete
WHERE condition;
WHERE Mob.No=2222;
SELECT INTO
- Select statement it is used to copies data from one table into a new table
ALIAS
SQL statement it is used for to change the temporary column name & table name without
changing the database
FROM tablename;
FROM SignUp;
Tablename- Register
UNION
UNION
SELECT LN FROM Register;
SignUp
Register
LN
1 Deshmukh
2 Gandhi
3 Hajare
4 Kejriwal
5 Pawar
6 Raut
7 Thakre
UNION
Seats
1 45
2 49
3 53
4 54
5 55
6 56
7 57
UNION ALL
UNION ALL
Output- 14
Create Table
Syntax
Column1 datatype,
Column1 datatype,
Column1 datatype,
);
Column parameter / attributes specify the names of the column of the table
Data type – specify the type of data the column can hold
ID int,
FN varchar(255)
LN varchar(255)
Mob.No int,
EmailId varchar(255)
City varchar(255)
)
Output- Structure
Tablename- SignUp
Drop
Truncate
- Truncate table statement is used to delete the all the records or delete the data inside the
table
- Not delete the structure of the table
- Only delete the all the records
Delete Truncate
DML command DDL command
We can use where clause We can not use where clause
Slower than truncate Faster than delete statement
Delete a row from table Remove all the rows
Can rollback data after using delete statement Not possible to rollback after using the truncate
statement
Alter
- Alter table statement is used to add, delete , modify column in an existing table
DROP address;
MY SQL / Oracal
Null, not null, default (puneVCTC), check (Age<22), primary key (ID), Unique key (ID,EmailId,
mob.no), forgain key (two link)
I have featch your all data – another table – primary key – another table – id- 1
Constraints
- Sql constraints are used to specify rules for the data in table
- Constraints are used to limit the type of data that can go in to a table
- Constraints – column apply or table
);
1. Null
2. Not null
3. Unique key
4. Primary key
5. Forgien key
6. Default
7. Check
1. Not null
- Column can not have null value
Ex.
);
Ex.
ID int NOTNULL,
FN varchar NOTNULL,
LN varchar NOTNULL
2. Unique key
- To ensure all the values in a column are different
- Unique constraints allow only one NULL value
- Each table have more that one/multiple unique key / value / constraints
CREATE TABLE SignUp
FN varchar NOTNULL,
LN varchar NOTNULL
Primary Key
FN varchar NOTNULL,
LN varchar NOTNULL
Default
FN varchar NOTNULL,
LN varchar NOTNULL
ID LN FN Age CITY
21 Pune
22 Pune
23 Pune
Check
FN varchar NOTNULL,
LN varchar NOTNULL
CHECK(Age) > 21
FORGIEN KEY
FN varchar NOTNULL,
LN varchar NOTNULL