DB Iq
DB Iq
Questions
© Copyright by Interviewbit
Contents
Introduction
Data Validity Testing: In this testing, testers need to know SQL queries to
retrieve data from the database and validate it.
Data Integrity Testing: Here, the testers need to validate data against various
constraints and referential integrity in the database.
Database Performance Testing: Here, the testers need to validate the
performance of various triggers, indices, procedures to see how effectively the
operations occur. The system also needs to execute database transactions
efficiently. Good knowledge of database structures needs to be there while
doing this.
Testing triggers, functions and procedures present in the database to validate
the logic associated with them.
There are 4 main types of data-driven testing based on the source of test data inputs:
Key-driven: Here, dynamic data is provided as inputs to the test cases by
employing a keyboard to retest the application and validate the business logic.
Flat files: Application retesting is done by taking input data stored in flat files
like .doc or .txt.
Front-end object: The test scripts use data from front-end objects like list, table,
menu, data window etc.
Spreadsheet/Excel: Here, the test data is taken from data stored in excel sheets
or spreadsheets.
We can use the statements like INSERT, UPDATE, SELECT, DELETE for manipulating
the table content. Statements like ALTER TABLE, DELETE TABLE, CREATE TABLE are
used for creating and managing the tables.
11. Explain with an example how you can test the database
manually?
Database testing can be done manually as well. This requires human effort in
observing the behaviour of the application when subjected to different manual test
cases dra ed by the testers. This can also involve observation of the behaviour in
front-end applications when the backend database has changed. We can also
manually check whether the record has been created, updated or deleted in the
database tables post the execution of the queries.
Consider an example of a database system that keeps track of student details. The
operations run on the Student tables database can be validated manually by looking
at the state of the records post query execution or can be validated in how the front
end interface looks like.
12. How do you validate whether the database table has been
updated a er you enter data from the front-end
application?
This depends on the front-end application’s interface which is being used. We can
test by using the following ways:
Check for the updated data in the front-end application’s view. The view should
be updated with the new value post successful insertion. This kind of testing
constitutes black box testing.
If there is no view available, then we can go to the database system, run the
select query and check for the data manually.
We can also use the WinRunner or QTP for checking the database update.
14. How will you know if a trigger is fired or not at the time of
database testing?
To know if a trigger is fired, we will have to enable the audit logs of the table. You can
refer to the steps to access logs here.
15. What are the different SQL statements that can be used for
database testing?
Following are the SQL statements categories that can be used in database testing:
Schema Testing: Here, the exact schema name should map between both front-
end and backend. The schema validation is very important because in some
cases, the schema of the tables would be different from the actual business
requirement and the front-end applications. This also involves verifying
unmapped tables or views or columns.
Tables Testing: This testing involves testing table names and testing columns.
The names mapped to frontend and backend should be the same and the
datatype and sizes of the columns should be as per the requirements specified
by the business. It also involves testing constraints applied to the tables and
columns. Furthermore, testing of indexes based on the property of clustered or
non-clustered and their functionality should also be tested accordingly.
Procedure and Function Testing: Here, the testers have to test the procedures
and functions available in the database and validate for the list of points below:
Did the team follow the business requirements correctly?
Is the code following good practices and proper naming conventions?
Are the parameters for input and output of these as per the expected
requirements?
Are the exceptions handled?
Are the procedures and functions inserting data to required tables
properly?
Are the procedures and functions updating/modifying data in the required
tables properly?
Trigger testing: The testing rules are similar to the procedure or functional
testing. In addition to those rules, we have to check if the triggers are getting
triggered/executed at required instants.
Database Server Testing: Test whether the database configurations, RAM,
capacity of processors, storage capacity etc based on the business requirements.
For testing the database triggers and procedures, it is required to know the input
parameters to these functionalities and know what would be the expected output for
these. The EXEC statement can be used for determining the behaviour of the tables
when the procedures or triggers are run.
You can also achieve this by creating SQL unit tests for checking the database objects
modified due to the execution of the triggers or procedures. The SQL unit tests follow
the 3 rules as shown below:
The test case should check whether the objects exist in the database or not. It should
check or validate what the normal outputs would be for success scenarios. It should
also check for the behaviour of the system under the influence of negative test cases.
20. What are the possible test scenarios that need to be tested
when a database gets migrated from one SQL server to
another?
Firstly, when migration happens, we need to be aware of all the changes and
enhancements are done in the new SQL server. Based on this information, design
your test case suite by considering the following points:
Transactions require the ACID properties to be satisfied. To achieve that, we use the
below statements:
ROLLBACK TRANSACTION#
The Rollback command ensures that the database changes are rolled back to the
previous stable commit and ensures consistency. Once the transactions are executed,
we can make use of SELECT queries to run on the tables where the transaction took
place and validate the data.
24. How can you validate the ACID properties? Explain with an
example.
Consider a simple SQL code below:
We will test for the ACID properties for two columns X and Y. There is also a constraint
added on the table that the sum of values in columns X and Y should always be 50.
Atomicity: Here, we test that the transactions done on the table is either
successful or failed. No records should be updated if the transactions fail.
Consistency: Here, we test that the values in columns X and Y are updated
correctly by following the constraint that the sum of these two values is always
50. The insertion or updation should not be allowed if the sum is not equal to 50.
Isolation: Here, in the presence of multiple transactions, we need to test they
are happening in isolation.
Durability: Here, the test cases should consider that if a transaction has been
committed, it should remain even a er the incidents of power losses, crashes
and errors. If we are using sharded or distributed database applications, rigorous
testing needs to be done to ensure the data is not lost.
25. How can you test the data integrity in database testing?
Whenever there are different modules in the application that are using the same data
and also perform different operations on them, it is very much necessary to have the
latest data to be shown everywhere. The most recent value of the data should be
used by the systems. This is called Data Integrity. Following image shows 5
characteristics of data following data integrity:
We can apply the following test cases for testing out the integrity of the data:
Are all the triggers working fine to update the records in the reference tables?
Are there any invalid data in the columns of each database?
Insert wrong data into the tables and see how the insertion behaves.
What would happen if you try to insert the child record before inserting the
parent record in the main table?
Is there any failure if you are trying to delete records referenced by another
table?
Are the replicated servers in sync? The data should not be out of sync in two or
more replicated servers as it would defy the intent of replication.
26. What are the most commonly occurring issues that are faced
during database testing and how can they be solved?
27. What are the best practices that need to be followed while
performing database testing?
Following are some good practices that need to be followed while performing
database testing:
Validate every single piece of data that includes metadata and functional data
based on the requirement specifications.
Test data should be verified and created a er consultation with the
development team and only then the validation needs to be done.
Output data needs to be validated by using both automated and manual
processes.
Perform boundary value analysis, graphing techniques, equivalence partitioning
techniques to get the required test data inputs.
The referential integrity of the data in the tables also needs to be carefully
evaluated.
The selection of default values in the table needs to be validated too to check for
consistency of data.
Check if appropriate logging events have been tracked and added to the
database.
Are the jobs scheduled to run are executed on time?
Ensure that timely backup of the test database is taken to ensure test cases do
not fail.
Ensure that the test server is periodically refreshed with close to real-time data
so that testing can be as accurate as possible.
28. How can you validate the tables and columns in the
database?
We can test the tables and columns in the databases by applying the following test
cases:
Are the database fields mapped correctly and is compatible with the required
mappings in the front-end or backend requirements?
Are the fields following proper naming conventions and have lengths and sizes
as per the requirements?
Check if there are any unused or unmapped tables and columns.
Check if the table design and the referential integrities and constraints on the
columns are applied effectively and are scalable to different requirements.
31. How will you fetch the values from TableA that are not
present in TableB without using the NOT keyword?
TableA
20
21
25
45
TableB
20
45
We can do it easily by using the SELECT and EXCEPT keywords as shown below:
32. What are the differences between GUI Testing and Database
Testing?
Conclusion
The need for correct data has grown exponentially in the so ware development field.
It is very crucial to use the right data, perform the right set of operations on it and
show the results to the right set of people. Due to this, database testing helps to
validate the correctness, integrity and truthfulness of the data. In this article, we have
seen the most commonly asked questions in database testing that deals with RDBMS
database systems to both freshers and experienced people.
Useful Resources:
DBMS Interview
SQL Interview
MYSQL Interview
Css Interview Questions Laravel Interview Questions Asp Net Interview Questions