Database testing

52
A CMMI Level 3 Company Database Testing Presented By Presented By Usha Naidu Usha Naidu Hrushikesh Wakhle Hrushikesh Wakhle

Transcript of Database testing

Page 1: Database testing

A CMMI Level 3 Company

Database Testing

Presented By Presented By Usha NaiduUsha Naidu Hrushikesh Wakhle Hrushikesh Wakhle

Page 2: Database testing

www.clariontechnologies.co.in

AgendaCRUD OperationsDatabase Testing ProcessACID PropertiesDDL DMLDCLTCLClauses ConstraintsJoins

Page 3: Database testing

www.clariontechnologies.co.in

Page 4: Database testing
Page 5: Database testing
Page 6: Database testing
Page 7: Database testing

www.clariontechnologies.co.in

Database Objects

Page 8: Database testing

Database Testing Process

Page 9: Database testing

www.clariontechnologies.co.in

SQL Commands

Page 10: Database testing

www.clariontechnologies.co.in

DDL – Data Definition Language

Page 11: Database testing

www.clariontechnologies.co.in

Create Database

Syntax:

CREATE DATABASE DatabaseName;

Always database name should be unique within the RDBMS.

Example:

If you want to create new database <testDB>, then CREATE DATABASE statement would be as follows:

SQL> CREATE DATABASE testDB;

SQL> SHOW DATABASES;

Show Database

Page 12: Database testing

www.clariontechnologies.co.in

Syntax :

ALTER TABLE table_nameADD column_name datatype

Example :

ALTER TABLE PersonsADD DateOfBirth date

Alter Table

- Mastering Selenium Testing Tools -

Hi Team,

Please refer this link for 1 month Free online Selenium training course with videos!!!https://www.linkedin.com/learning/mastering-selenium-testing-tools/the-course-overview

Thanks

Drop Table Syntax: DROP TABLE TableName;

SQL> DROP TABLE CUSTOMERS;

SQL> SHOW CUSTOMERS;

Page 13: Database testing

www.clariontechnologies.co.in

Syntax:

TRUNCATE TABLE table_name;

SQL > TRUNCATE TABLE CUSTOMERS;

Now, CUSTOMERS table is truncated and following would be the output from SELECT statement:

SQL> SELECT * FROM CUSTOMERS;

Empty set (0.00 sec)

Truncate

Page 14: Database testing

www.clariontechnologies.co.in

TCL – Transaction Control Language

Page 15: Database testing

www.clariontechnologies.co.in

Syntax:

SAVEPOINT SAVEPOINT_NAME;

Savepoint

Page 16: Database testing

www.clariontechnologies.co.in

Syntax:

COMMIT;

Commit

Page 17: Database testing

www.clariontechnologies.co.in

Syntax:

ROLLBACK;

SQL> DELETE FROM CUSTOMERS WHERE AGE = 25;

SQL> ROLLBACK;

Rollback

Page 18: Database testing

www.clariontechnologies.co.in

DML – Data Manipulation Language

Page 19: Database testing

www.clariontechnologies.co.in

SELECT

Syntax :

SELECT column_name1 ,column_name2, column_name3,… column_namenFROM table_name;

SELECT * FROM table_name;

SQL> SELECT * FROM CUSTOMERS;

SQL> SELECT ID, NAME, SALARY FROM CUSTOMERS;

Page 20: Database testing

www.clariontechnologies.co.in

Insert

Syntax :

INSERT INTO TABLE_NAME (column1, column2, column3,...columnN)] VALUES (value1, value2, value3,...valueN);

SQL> INSERT INTO CUSTOMERS VALUES (7, 'Muffy', 24, 'Indore', 10000.00 );

Page 21: Database testing

www.clariontechnologies.co.in

UpdateSyntax :

UPDATE table_nameSET column1 = value1, column2 = value2...., columnN = valueNWHERE [condition];

SQL> UPDATE CUSTOMERSSET ADDRESS = 'Pune'WHERE ID = 6;

Page 22: Database testing

www.clariontechnologies.co.in

Delete

Syntax :

DELETE FROM table_nameWHERE [condition];

SQL> DELETE FROM CUSTOMERSWHERE ID = 6;

Page 23: Database testing

www.clariontechnologies.co.in

DCL – Data Control Language

Page 24: Database testing

www.clariontechnologies.co.in

GRANTSyntax :

GRANT privilege_name ON object_name ;

Examples :

SQL> GRANT SELECT, INSERT, UPDATE, DELETE ON employees TO smithj;

SQL> GRANT ALL ON employees TO smithj;

SQL> GRANT SELECT ON employees TO public;

Page 25: Database testing

REVOKE

Syntax :

REVOKE privilege_name ON object_name FROM user_name;

Examples :

SQL> REVOKE privileges ON object FROM user;

SQL> REVOKE ALL ON employees FROM anderson;

SQL> REVOKE SELECT ON employees FROM public;;

Page 26: Database testing

www.clariontechnologies.co.in

Clauses

Page 27: Database testing

www.clariontechnologies.co.in

Where Clause

Syntax :

SELECT column1, column2, columnN FROM table_nameWHERE [condition]

SQL> SELECT ID, NAME, SALARY FROM CUSTOMERSWHERE SALARY > 2000;

Page 28: Database testing

www.clariontechnologies.co.in

Order By Clause

Syntax :

SELECT column-list FROM table_name [WHERE condition] [ORDER BY column1, column2, .. columnN] [ASC | DESC];

SQL> SELECT * FROM CUSTOMERS ORDER BY NAME, SALARY;

Page 29: Database testing

www.clariontechnologies.co.in

Group By Clause

Syntax :

SELECT column1, column2FROM table_nameWHERE [ conditions ]GROUP BY column1, column2ORDER BY column1, column2

SQL> SELECT NAME, SUM(SALARY) FROM CUSTOMERS GROUP BY NAME;

Page 30: Database testing

www.clariontechnologies.co.in

TOP Clause

Syntax :

SELECT TOP number|percent column_name(s)FROM table_nameWHERE [condition]

SELECT TOP 3 FROM CUSTOMERSWHERE SALARY <= 2000

Page 31: Database testing

www.clariontechnologies.co.in

Like ClauseSyntax:

The basic syntax of % and _ is as follows:SELECT FROM table_name WHERE column LIKE 'XXXX%‘ or SELECT FROM table_name WHERE column LIKE '%XXXX%‘ or SELECT FROM table_name WHERE column LIKE 'XXXX_‘ or SELECT FROM table_name WHERE column LIKE '_XXXX' or SELECT FROM table_name WHERE column LIKE '_XXXX_‘

SQL> SELECT * FROM CUSTOMERSWHERE SALARY LIKE '200%';

Page 32: Database testing

www.clariontechnologies.co.in

Having Clause

Syntax :

SELECT column1, column2FROM table1, table2WHERE [ conditions ]GROUP BY column1, column2HAVING [ conditions ]ORDER BY column1, column2

SQL > SELECT ID, NAME, AGE, ADDRESS, SALARYFROM CUSTOMERSGROUP BY ageHAVING COUNT(age) >= 2;

Page 33: Database testing

www.clariontechnologies.co.in

Page 34: Database testing

www.clariontechnologies.co.in

Not Null Constraint

By default, a column can hold NULL values. If you do not want a column to have a NULL value, then you need to define such constraint on this column specifying that NULL is now not allowed for that column.

A NULL is not the same as no data, rather, it represents unknown data.

Page 35: Database testing

www.clariontechnologies.co.in

Default Constraint

The DEFAULT constraint provides a default value to a column when the INSERT INTO statement does not provide a specific value.

Page 36: Database testing

www.clariontechnologies.co.in

UNIQUE Constraint

The UNIQUE Constraint prevents two records from having identical values in a particular column. In the CUSTOMERS table, for example, you might want to prevent two or more people from having identical age.

Page 37: Database testing

www.clariontechnologies.co.in

Primary Constraint

A primary key is a field in a table which uniquely identifies each row/record in a database table. Primary keys must contain unique values. A primary key column cannot have NULL values.

Page 38: Database testing

www.clariontechnologies.co.in

Foreign Key Constraint

A foreign key is a key used to link two tables together. This is sometimes called a referencing key.

Foreign Key is a column or a combination of columns whose values match a Primary Key in a different table.

The relationship between 2 tables matches the Primary Key in one of the tables with a Foreign Key in the second table.

Page 39: Database testing

www.clariontechnologies.co.in

Check Constraints

The CHECK Constraint enables a condition to check the value being entered into a record. If the condition evaluates to false, the record violates the constraint and isn't entered into the table.

Page 40: Database testing

www.clariontechnologies.co.in

Joins

Joins clause is used to combine records from two or more tables in a database. A JOIN is a means for combining fields from two tables by using values common to each.

SQL> SELECT ID, NAME, AGE, AMOUNT FROM CUSTOMERS, ORDERS WHERE CUSTOMERS.ID = ORDERS.CUSTOMER_ID;

Page 41: Database testing

www.clariontechnologies.co.in

LEFTLEFT

RIGHRIGHTT

FULLFULL

Types Of JOINS

Page 42: Database testing

www.clariontechnologies.co.in

CROSS JOIN or CARTESIAN PRODUCT

Syntax :

SELECT table1.column1, table2.column2... FROM table1, table2 [, table3 ]

SQL> SELECT ID, NAME, AMOUNT, DATE FROM CUSTOMERS, ORDERS;

Page 43: Database testing

NATURAL JOINThe SQL NATURAL JOIN is a type of EQUI JOIN and is structured in such a way that, columns with the same name of associated tables will appear once only.

Natural Join : Guidelines

- The associated tables have one or more pairs of identically named columns.- The columns must be the same data type.- Don’t use ON clause in a natural join.

Syntax

SELECT * FROM table1 NATURAL JOIN table2;

SQL> SELECT *  

FROM foods   

NATURAL JOIN company;  

www.clariontechnologies.co.in

Page 44: Database testing

www.clariontechnologies.co.in

INNER JOIN

Syntax :

SELECT table1.column1, table2.column2...FROM table1INNER JOIN table2ON table1.common_field = table2.common_field;

SQL> SELECT ID, NAME, AMOUNT, DATE FROM CUSTOMERS INNER JOIN ORDERS ON CUSTOMERS.ID = ORDERS.CUSTOMER_ID;

Page 45: Database testing

www.clariontechnologies.co.in

LEFT JOIN

Syntax :

SELECT table1.column1, table2.column2...FROM table1LEFT JOIN table2ON table1.common_field = table2.common_field;

SQL> SELECT ID, NAME, AMOUNT, DATE FROM CUSTOMERS LEFT JOIN ORDERS ON CUSTOMERS.ID = ORDERS.CUSTOMER_ID;

Page 46: Database testing

www.clariontechnologies.co.in

RIGHT JOIN

Syntax :

SELECT table1.column1, table2.column2...FROM table1RIGHT JOIN table2ON table1.common_field = table2.common_field;

SQL> SELECT ID, NAME, AMOUNT, DATE FROM CUSTOMERS RIGHT JOIN ORDERS ON CUSTOMERS.ID = ORDERS.CUSTOMER_ID;

Page 47: Database testing

www.clariontechnologies.co.in

FULL JOIN

Syntax :

SELECT table1.column1, table2.column2...FROM table1FULL JOIN table2ON table1.common_field = table2.common_field;

SQL> SELECT ID, NAME, AMOUNT, DATE FROM CUSTOMERS FULL JOIN ORDERS ON CUSTOMERS.ID = ORDERS.CUSTOMER_ID;

Page 48: Database testing

www.clariontechnologies.co.in

SELF JOIN

Syntax :

SELECT table1.column1, table2.column2...FROM table1RIGHT JOIN table2ON table1.common_field = table2.common_field;

SQL> SELECT ID, NAME, AMOUNT, DATE FROM CUSTOMERS RIGHT JOIN ORDERS ON CUSTOMERS.ID = ORDERS.CUSTOMER_ID;

Page 49: Database testing

Myths or Misconceptions related to Database Testing• Database Testing requires plenty of expertise and it is a very tedious job

Reality: Effective and efficient Database testing provides long-term functional stability to the overall application thus it is necessary to put in hard work behind it.

• Database testing adds extra work bottleneck

Reality: On the contrary, database testing adds more value to the overall work by finding out hidden issues and thus pro-actively helping to improve the overall application.

• Database testing slows down the overall development process

Reality: Significant amount of database testing helps in the overall improvement of quality for the database application.

• Database testing could be excessively costly

Reality: Any expenditure on database testing is a long-term investment which leads to long-term stability and robustness of the application. Thus expenditure on database testing is necessary.

www.clariontechnologies.co.in

Page 50: Database testing

www.clariontechnologies.co.in

• ACID (Atomicity, Consistency, Isolation, Durability) is a set of properties of database transactions. It allows safe sharing of data.

• Create, Read, Update and Delete (as an acronym CRUD) are the four basic functions of persistent storage

• With all the features, factors and processes to test on a database, there is an increasing demand on the tester to be technically strong with the key DB concepts. Despite some of negative beliefs that the DB testing creates new bottlenecks and is a lot of additional expenditure – this is a realm of testing that is gaining obvious attention and demand.

• Since your test design would require creating SQL queries, try to keep your queries as simple as possible to prevent defects in them. It is a good idea for someone other than the author to review the queries.

SUMMARSUMMARYY

Page 51: Database testing

www.clariontechnologies.co.in

Referenceshttp://www.studytonight.com/dbms/joining-in-sql.php

https://www.codecademy.com/learn/learn-sql

http://www.softwaretestinghelp.com/database-testing-process/

https://en.wikipedia.org/wiki/SQL

http://www.w3schools.com/sql/

https://www.khanacademy.org/computing/computer-programming/sql

http://www.sqlcourse.com/intro.html

http://www.tutorialspoint.com/sql/

Page 52: Database testing

A CMMI Level 3 Company

Thank You!Thank You!

[email protected]