Database Testing

Database Testing

Top Interview Questions

About Database Testing

 

Database Testing: An In-Depth Overview

Database testing is a crucial aspect of software quality assurance that focuses on validating the integrity, consistency, and reliability of data stored in a database. In modern applications, databases serve as the backbone, storing critical business data and ensuring smooth operation of software systems. Unlike functional testing, which primarily focuses on the user interface or application logic, database testing dives deep into the backend, examining data structures, data manipulation operations, and their adherence to business rules.

Importance of Database Testing

Databases are central to most applications, whether it is an e-commerce platform, banking system, healthcare application, or enterprise software. Any flaw in the database can lead to incorrect reports, business losses, or even system failures. Database testing ensures that the data retrieved, stored, or manipulated is accurate and consistent with the application requirements. Key reasons why database testing is essential include:

  1. Data Integrity: Ensures that the data remains accurate and consistent across all operations.

  2. Reliability of Data Retrieval: Verifies that queries fetch the correct data according to business logic.

  3. Compliance with Business Rules: Confirms that the database constraints, triggers, and stored procedures adhere to defined rules.

  4. Performance Optimization: Detects slow queries or performance bottlenecks, ensuring fast response times.

  5. Security: Checks data access restrictions and prevents unauthorized operations on sensitive information.

Without proper database testing, applications may work correctly from the user interface perspective but fail in delivering reliable data outputs, leading to significant operational issues.

Objectives of Database Testing

Database testing has several objectives, all aimed at maintaining the robustness and reliability of the database systems:

  1. Validation of Schema: Ensures that tables, columns, keys, and relationships are correctly implemented according to the design.

  2. Data Accuracy: Verifies that data stored matches the intended input and is correctly processed.

  3. Stored Procedure and Trigger Testing: Ensures that business logic embedded in the database functions correctly.

  4. Transaction Testing: Validates that database transactions (insert, update, delete) are atomic, consistent, isolated, and durable (ACID compliant).

  5. Backup and Recovery Testing: Checks whether the database can be restored correctly after failure or crash.

  6. Data Integrity Testing: Ensures that relationships among data entities are maintained and constraints are enforced.

Types of Database Testing

Database testing can be broadly categorized into several types, each focusing on a specific aspect of the database:

1. Structural Testing

Structural testing, also known as schema testing, focuses on verifying the design and structure of the database. It includes:

  • Validation of tables, columns, primary keys, and foreign keys.

  • Checking indexes, constraints, and triggers.

  • Ensuring normalization to eliminate data redundancy.

  • Confirming data types and default values for each field.

2. Functional Testing

Functional testing validates that database operations perform as expected. This includes:

  • Verifying that stored procedures, functions, and triggers work correctly.

  • Checking the execution of CRUD (Create, Read, Update, Delete) operations.

  • Ensuring that business rules defined in the database are enforced accurately.

3. Non-Functional Testing

Non-functional database testing checks performance, scalability, and security aspects, including:

  • Performance Testing: Measures query execution time, indexing efficiency, and response under load.

  • Security Testing: Validates user roles, permissions, and access restrictions.

  • Backup and Recovery Testing: Ensures database can be restored to a previous state without data loss.

4. Regression Testing

Whenever the database schema or business logic is updated, regression testing ensures that the existing functionality is not affected. This includes testing previously validated stored procedures, triggers, and queries after modifications.

5. Data Migration Testing

In scenarios where data is migrated from legacy systems or other databases, data migration testing ensures:

  • All data is migrated accurately.

  • Relationships between data entities are preserved.

  • Data quality is maintained post-migration.

Database Testing Techniques

Several techniques are employed in database testing to ensure comprehensive coverage:

1. Black Box Testing

In black box testing, testers validate database operations without considering the internal implementation. The focus is on input and output, ensuring data stored matches expectations. For example, inserting customer data via an application form should correctly reflect in the database.

2. White Box Testing

White box testing involves examining the internal database logic. Testers check stored procedures, triggers, functions, and SQL queries for correctness. This technique ensures that all logical paths are tested for proper functionality.

3. SQL Query Testing

SQL query testing is essential in database testing. Testers validate queries for:

  • Accuracy: Whether queries return the correct data.

  • Efficiency: Whether queries are optimized for performance.

  • Safety: Whether queries prevent SQL injection or unauthorized access.

4. Data Integrity Testing

Data integrity testing ensures that the database maintains consistency and accuracy over its lifecycle. This includes:

  • Entity Integrity: Primary keys must be unique and not null.

  • Referential Integrity: Foreign keys must correctly reference primary keys in related tables.

  • Domain Integrity: Data values must be within defined constraints.

  • User-Defined Integrity: Custom rules specific to business logic must be enforced.

5. Transaction Testing

Transactions are critical in ensuring that operations are executed reliably. Transaction testing verifies:

  • Atomicity: Either all steps of a transaction succeed, or none do.

  • Consistency: Database remains in a valid state after a transaction.

  • Isolation: Transactions do not interfere with each other.

  • Durability: Changes made by a transaction persist after system failure.

Database Testing Tools

Several tools can automate or assist in database testing, increasing efficiency and coverage:

  1. Selenium with JDBC: Selenium can automate UI interactions while JDBC connects to the database for validation.

  2. QTP/UFT: Unified Functional Testing tools allow both UI and database validation.

  3. SQL Server Management Studio (SSMS): Useful for testing SQL Server databases manually.

  4. Oracle SQL Developer: Used for testing Oracle databases and executing queries.

  5. DbUnit: Java-based tool for database unit testing.

  6. Tosca Testsuite: Supports database testing along with UI and API testing.

Automation in database testing reduces repetitive manual work and ensures accurate verification of complex queries and transactions.

Challenges in Database Testing

Database testing is complex and comes with several challenges:

  1. Large Volume of Data: Modern databases store millions of records, making manual validation difficult.

  2. Complex Relationships: Ensuring consistency across multiple related tables can be challenging.

  3. Dynamic Data: Real-time applications continuously modify data, complicating testing scenarios.

  4. Performance Bottlenecks: Identifying inefficient queries or indexing issues requires deep expertise.

  5. Security Concerns: Testing sensitive data without breaching privacy regulations is critical.

  6. Synchronization Issues: Distributed databases may face synchronization or replication problems during testing.

Addressing these challenges requires careful planning, a combination of manual and automated testing, and skilled database testers.

Best Practices in Database Testing

To ensure effective database testing, organizations should follow best practices:

  1. Understand the Database Design: Knowledge of schema, relationships, and business logic is critical before testing.

  2. Use a Staging Environment: Avoid testing directly on production databases to prevent accidental data loss.

  3. Automate Repetitive Tests: Use tools to automate query validation, data integrity checks, and regression testing.

  4. Test Data Variety: Use a combination of valid, invalid, boundary, and stress data for comprehensive coverage.

  5. Maintain Test Scripts: Keep SQL scripts organized, reusable, and maintainable.

  6. Perform Regular Backups: Ensure backup and recovery processes are validated periodically.

  7. Collaborate with Developers: Coordinate with database developers to understand complex logic and triggers.

  8. Include Security and Compliance Checks: Ensure sensitive data is encrypted and access permissions are correctly implemented.

Future Trends in Database Testing

Database testing continues to evolve with technology advancements. Some trends include:

  1. Cloud Database Testing: As more applications migrate to cloud-based databases like AWS RDS, Azure SQL, and Google Cloud SQL, testing in cloud environments becomes essential.

  2. Big Data Testing: Testing massive datasets in technologies like Hadoop and Spark requires specialized strategies.

  3. Automated Regression Testing: Advanced automation frameworks can run continuous database validation during DevOps pipelines.

  4. AI-Driven Testing: Artificial intelligence can optimize query testing, detect anomalies, and predict performance issues.

 

Fresher Interview Questions

 

1. What is Database Testing?

Answer:
Database Testing is the process of testing the database to ensure data integrity, consistency, reliability, and correct behavior of database operations. It involves validating the data stored in tables, relationships, and transactions to ensure the application behaves as expected.

Key points to mention:

  • Ensures data consistency between the application and the database.

  • Verifies SQL queries and stored procedures.

  • Checks triggers, constraints, and indexes.

  • Validates database performance and security.


2. What are the types of Database Testing?

Answer:
Database Testing can be categorized into the following types:

  1. Structural Testing (White Box Testing):

    • Verifies database structures such as tables, columns, indexes, and constraints.

  2. Functional Testing (Black Box Testing):

    • Validates whether database operations meet the business requirements.

  3. Non-Functional Testing:

    • Includes performance, scalability, reliability, and security testing of the database.

  4. Data Integrity Testing:

    • Ensures data is accurate and consistent across the database.

  5. Transactional Testing:

    • Checks whether transactions are committed or rolled back correctly.


3. What is Data Integrity?

Answer:
Data Integrity refers to maintaining accuracy and consistency of data in the database over its entire lifecycle.
Types of Data Integrity:

  • Entity Integrity: Ensures primary keys are unique and not null.

  • Referential Integrity: Ensures foreign keys match primary keys in another table.

  • Domain Integrity: Validates data type, format, and range of values.

  • User-Defined Integrity: Business-specific rules applied to the database.


4. What are the common SQL commands used in Database Testing?

Answer:
The main SQL commands are:

  • DDL (Data Definition Language): CREATE, ALTER, DROP

  • DML (Data Manipulation Language): SELECT, INSERT, UPDATE, DELETE

  • DCL (Data Control Language): GRANT, REVOKE

  • TCL (Transaction Control Language): COMMIT, ROLLBACK, SAVEPOINT


5. How do you test a database?

Answer:
Steps to perform database testing:

  1. Requirement Analysis:

    • Understand the business logic, data model, and expected outputs.

  2. Test Case Preparation:

    • Prepare SQL queries to validate data in tables.

  3. Data Validation:

    • Check whether data entered through the application is correctly stored in the database.

  4. Data Integrity Testing:

    • Verify relationships, constraints, and triggers.

  5. Query Testing:

    • Validate stored procedures, views, functions, and triggers.

  6. Transaction Testing:

    • Ensure proper commit and rollback mechanisms are working.

  7. Performance Testing:

    • Validate indexing, query response time, and database performance.


6. What is the difference between Database Testing and Application Testing?

Aspect Database Testing Application Testing
Focus Data, queries, integrity, and transactions User interface, functionality, and workflow
Type Back-end testing Front-end testing
Tools SQL, DBUnit, Oracle, MySQL Selenium, QTP, JMeter
Goal Ensure correct storage, retrieval, and integrity Ensure software meets business requirements

7. What are ACID properties in database testing?

Answer:
ACID properties are the fundamental rules of database transactions:

  1. Atomicity: Transaction is all or nothing (either fully completed or fully rolled back).

  2. Consistency: Database remains in a valid state before and after the transaction.

  3. Isolation: Transactions do not interfere with each other.

  4. Durability: Once a transaction is committed, changes are permanent.


8. What are triggers, and how do you test them?

Answer:
Triggers are stored procedures automatically executed when certain events occur on a table, such as INSERT, UPDATE, or DELETE.

Testing Triggers:

  1. Insert, update, or delete data to check trigger execution.

  2. Validate if the trigger correctly modifies data or logs actions.

  3. Ensure it doesn’t violate data integrity.


9. What is a stored procedure, and how do you test it?

Answer:
A stored procedure is a set of SQL statements stored in the database that can be executed repeatedly.

Testing steps:

  1. Execute stored procedure with valid inputs.

  2. Validate output against expected results.

  3. Test with invalid inputs to verify error handling.

  4. Check transaction management within the procedure.


10. What are the common database constraints?

Answer:
Constraints enforce rules on data in tables:

  • Primary Key (PK): Unique identifier for a table row.

  • Foreign Key (FK): Ensures referential integrity with another table.

  • Unique: Ensures column values are unique.

  • Not Null: Column must have a value.

  • Check: Restricts values based on a condition.

  • Default: Provides a default value if none is supplied.


11. How do you validate data in database testing?

Answer:
Data validation involves checking:

  1. Consistency: Compare database values with application input.

  2. Accuracy: Correct calculations, aggregations, and sums.

  3. Completeness: No missing or null values where mandatory.

  4. Referential integrity: All foreign key references are correct.


12. What is the difference between OLTP and OLAP databases?

Feature OLTP OLAP
Purpose Transaction processing Analytical processing
Data Volume Small, frequent transactions Large, historical data
Query Type Simple, fast queries Complex queries
Example Banking system, e-commerce Data warehouse, BI reports

13. What tools are used in Database Testing?

Answer:

  • SQL Developer / TOAD: Execute queries, test procedures, and triggers.

  • DBUnit: Java-based testing framework.

  • Selenium + JDBC: For end-to-end testing.

  • Data Factory / Informatica: ETL testing.

  • QuerySurge: Automates ETL and database testing.


14. What is the difference between Inner Join, Left Join, Right Join, and Full Join?

Join Type Description
Inner Join Returns matching rows from both tables
Left Join Returns all rows from the left table and matched rows from right
Right Join Returns all rows from the right table and matched rows from left
Full Join Returns all rows when there is a match in either table

15. How do you test a database after migration?

Answer:

  1. Compare row counts of source and target tables.

  2. Validate data accuracy by sampling critical records.

  3. Verify constraints, triggers, and stored procedures.

  4. Test application functionality using migrated data.

  5. Ensure performance and indexing is not affected.


16. What is ETL Testing?

Answer:
ETL Testing (Extract, Transform, Load) ensures data is correctly extracted from the source, transformed as per business rules, and loaded into the target database or data warehouse.
Focus Areas:

  • Data completeness

  • Data accuracy

  • Transformation logic verification

  • Performance of ETL processes


17. What are common challenges in Database Testing?

Answer:

  • Handling large volumes of data.

  • Complex business rules for validation.

  • Testing stored procedures and triggers.

  • Maintaining test environments consistent with production.

  • Ensuring data integrity after migrations or updates.


18. How do you perform performance testing on a database?

Answer:

  • Monitor query execution time.

  • Check index usage and optimize queries.

  • Test concurrent user access.

  • Validate database response time for high volumes.

  • Identify and fix bottlenecks like locking or deadlocks.


19. Can you test a database without a front-end application?

Answer:
Yes. Using tools like SQL Developer, TOAD, or DBUnit, you can:

  • Execute SQL queries directly.

  • Run stored procedures.

  • Insert, update, and delete test data.

  • Validate outputs, triggers, and constraints.


20. Best practices for Database Testing

  • Prepare a detailed test plan including all tables, constraints, and procedures.

  • Use sample test data and boundary cases.

  • Automate repetitive query validations.

  • Ensure data integrity after each transaction.

  • Document test cases and expected vs actual results.


πŸ’‘ Tips for Freshers:

  • Learn basic SQL queries: SELECT, JOIN, GROUP BY, HAVING, ORDER BY.

  • Understand relational database concepts and table relationships.

  • Practice testing stored procedures and triggers on a sample database.

  • Know the difference between OLTP and OLAP.

  • Be prepared for scenario-based questions: e.g., “If a transaction fails, how do you verify rollback?”


 

21. What is a database schema?

Answer:
A database schema is the blueprint of a database. It defines how data is organized and how the relationships between tables are structured.

  • Types of schema:

    • Physical Schema: How data is physically stored.

    • Logical Schema: How data is logically organized (tables, views, keys).

  • Example: Tables for Employees, Departments with relationships.


22. What is normalization? Why is it important?

Answer:
Normalization is the process of organizing data in a database to reduce redundancy and improve data integrity.

  • Forms of normalization:

    • 1NF: Eliminate repeating groups.

    • 2NF: Remove partial dependencies.

    • 3NF: Remove transitive dependencies.

  • Importance:

    • Reduces duplicate data.

    • Ensures consistency and efficient storage.

    • Makes maintenance easier.


23. What is denormalization? When is it used?

Answer:
Denormalization is the process of introducing redundancy to improve query performance.

  • When used:

    • When complex joins reduce performance.

    • For reporting databases or OLAP systems.

  • Trade-off: Improved performance but increased storage and maintenance.


24. What are indexes, and how do you test them?

Answer:
Indexes are database structures that improve query performance by reducing search time.

Testing Indexes:

  • Validate that queries execute faster with indexes.

  • Check whether indexes exist for frequently searched columns.

  • Test insert/update/delete operations to ensure indexes are updated.


25. What is a deadlock? How can it be tested?

Answer:
A deadlock occurs when two or more transactions wait for each other to release locks, causing the system to halt.

Testing Deadlocks:

  • Simulate multiple concurrent transactions.

  • Use DB tools to monitor locks.

  • Check whether the database handles deadlocks (abort or rollback one transaction).


26. How do you verify database triggers?

Answer:

  1. Identify the type of trigger (BEFORE/AFTER, INSERT/UPDATE/DELETE).

  2. Execute the corresponding action in the application or SQL.

  3. Check if the trigger executed correctly (e.g., logging, updating another table).

  4. Verify that no unintended changes occurred.


27. What is the difference between DELETE and TRUNCATE?

Feature DELETE TRUNCATE
Deletes rows Yes, based on condition All rows
DML/DDL DML DDL
Transaction log Logged Minimal logging
Rollback Can rollback Can rollback in some DBs (depends on RDBMS)
Triggers Activates triggers Doesn’t activate triggers

28. What is the difference between a primary key and unique key?

Feature Primary Key Unique Key
Null values Not allowed Allowed (in some DBs, usually 1 null)
Uniqueness Ensures unique record Ensures unique value
Number of keys per table One Multiple
Purpose Identifies record Prevents duplicates

29. How do you test stored procedures with input parameters?

Answer:

  1. Identify input parameters and expected outputs.

  2. Execute procedure with valid input and validate outputs.

  3. Execute with invalid or edge case input to check error handling.

  4. Test transaction behavior (COMMIT/ROLLBACK).


30. What is a view, and how do you test it?

Answer:
A view is a virtual table created from a query of one or more tables.

Testing Views:

  • Check if the view displays correct data.

  • Test join and filter conditions used in the view.

  • Validate that updates or inserts through views work as expected (if allowed).


31. What is a cursor in SQL, and how do you test it?

Answer:
A cursor is a database object that retrieves rows one by one from a result set.

Testing Cursors:

  • Open the cursor and fetch rows sequentially.

  • Validate that the fetched data matches the query.

  • Close the cursor and ensure no resource leaks occur.


32. Explain the difference between Clustered and Non-Clustered Index.

Feature Clustered Index Non-Clustered Index
Data storage Sorts data physically Separate structure
Only one per table Yes Multiple allowed
Query performance Faster for range queries Slower than clustered
Use case Primary key column Search-heavy columns

33. How do you handle NULL values in database testing?

Answer:

  • Verify that mandatory columns don’t accept NULL.

  • Check whether queries handle NULL correctly using IS NULL or COALESCE().

  • Validate reports and calculations for NULL handling.

  • Test default values for optional columns.


34. What is data migration testing?

Answer:
Data migration testing validates that data moved from source to target is accurate, complete, and consistent.

Steps:

  1. Compare row counts between source and target.

  2. Validate data mapping rules and transformations.

  3. Test primary/foreign key relationships.

  4. Validate triggers, stored procedures, and views.


35. Explain scenario-based question: “If a transaction fails midway, how do you verify rollback?”

Answer:

  1. Execute a transaction with multiple DML operations.

  2. Introduce an error in one operation.

  3. Verify that none of the previous operations are committed.

  4. Check database logs and ensure data integrity.


36. What are sequences in a database?

Answer:

  • A sequence generates unique numbers automatically.

  • Used for primary keys or auto-increment values.

  • Testing sequences:

    • Verify correct increment values.

    • Check restart behavior after deletion or rollback.

    • Ensure uniqueness across concurrent transactions.


37. What is a materialized view, and how is it different from a normal view?

Feature Normal View Materialized View
Storage No storage Stores data physically
Updates Always reflects real-time data Needs refresh to update data
Performance Slower for large datasets Faster as data is precomputed
Use Case Simple reporting Aggregated reporting

38. How do you perform database testing in Agile projects?

Answer:

  • Work in short iterations with developers.

  • Write SQL queries to validate database changes for each sprint.

  • Use automation tools for repeated regression testing.

  • Validate data integrity after frequent deployments.


39. How to test database security?

Answer:

  • Check user roles and privileges.

  • Verify that unauthorized users cannot access tables or data.

  • Test SQL injection vulnerabilities.

  • Ensure audit logs are maintained.


40. How do you validate data in an ETL process?

Answer:

  • Compare source vs target row counts.

  • Validate transformation rules applied correctly.

  • Check primary/foreign key relationships.

  • Verify aggregate functions and calculations.

  • Test incremental and full load processes.


41. What are orphan records, and how do you detect them?

Answer:

  • Orphan records: Records in a child table without a matching parent record.

  • Detection query:

SELECT * FROM ChildTable c
LEFT JOIN ParentTable p ON c.ParentID = p.ID
WHERE p.ID IS NULL;
  • Important for data integrity testing.


42. Explain the difference between UNION and UNION ALL.

Feature UNION UNION ALL
Duplicates Removes duplicates Keeps duplicates
Performance Slower (removes duplicates) Faster
Use Case Combine unique records Combine all records

43. What is referential integrity testing?

Answer:

  • Ensures that foreign key values match primary key values in another table.

  • Testing steps:

    1. Insert valid child records and verify success.

    2. Insert invalid child records and verify error.

    3. Delete parent records and check cascade or restrict behavior.


44. How do you test database backup and restore?

Answer:

  1. Perform a database backup.

  2. Delete or corrupt some data in the database.

  3. Restore database from backup.

  4. Verify that data, structure, and relationships are intact.


45. Explain the difference between RDBMS and DBMS.

Feature DBMS RDBMS
Data storage File-based Table-based with relationships
Relationships Not enforced Enforced via keys
SQL support Limited Full SQL support
Example Microsoft Access Oracle, MySQL, SQL Server

 

Experienced Interview Questions

 

1. Explain Database Testing in your own words.

Answer:
Database Testing is validating the back-end database to ensure that data is accurate, consistent, secure, and performs well.

  • Includes verification of tables, views, triggers, stored procedures, indexes, constraints, and transactions.

  • Focuses on data integrity, performance, and security.

  • Also includes ETL, migration, and API data verification.


2. How do you validate data integrity in a large database?

Answer:

  1. Use SQL queries to verify primary key, foreign key, and unique constraints.

  2. Validate referential integrity between parent and child tables.

  3. Compare source vs target datasets (for migrations).

  4. Sample data with boundary and negative cases.

  5. Use automation scripts (Python, Java, or SQL) for repetitive checks.


3. What is the difference between OLTP and OLAP in testing context?

Feature OLTP OLAP
Purpose Transaction processing Analytical reporting
Data Current, small Historical, large
Queries Short, simple Complex, aggregations
Testing Focus CRUD operations, ACID Aggregations, ETL, performance
Example Banking system Data warehouse

Answer:
For experienced testers, OLTP testing focuses on transaction accuracy, ACID compliance, while OLAP testing focuses on ETL validation, aggregation accuracy, and performance of analytical queries.


4. What are the key points to test in ETL/ETL Database Testing?

Answer:

  1. Data Completeness: All records from source loaded into target.

  2. Data Accuracy: Values match after transformation.

  3. Transformation Rules: Business rules applied correctly.

  4. Data Type Validation: Target column types match expected formats.

  5. Performance: ETL loads executed within SLA.

  6. Error Handling: Invalid data logged correctly.

  7. Incremental Loads: Only new/changed records updated.


5. How do you perform database performance testing?

Answer:

  1. Identify heavy queries or frequent stored procedures.

  2. Measure query execution time using EXPLAIN PLAN or profiling tools.

  3. Test concurrent transactions for locking, deadlocks, and contention.

  4. Check indexes and optimize queries.

  5. Monitor CPU, memory, and disk I/O for database performance.

  6. Use tools like SQL Profiler, Oracle AWR, Query Analyzer.


6. Explain ACID properties and how you validate them practically.

Answer:

  • Atomicity: Ensure a transaction either commits fully or rolls back completely.

  • Consistency: Verify that constraints and rules are enforced after transactions.

  • Isolation: Test concurrent transactions do not interfere with each other.

  • Durability: Committed transactions persist after crash/restart.

Validation Example:

  • Create a multi-step transaction and intentionally cause an error to verify rollback (atomicity).

  • Simulate concurrent updates to test isolation levels.


7. How do you test triggers in a production database?

Answer:

  1. Identify the trigger type (INSERT/UPDATE/DELETE, BEFORE/AFTER).

  2. Perform the triggering action and validate its effect (e.g., audit table insert).

  3. Test boundary and negative scenarios.

  4. Ensure triggers do not cause performance issues.

  5. Monitor logs and error handling.


8. Difference between Stored Procedures and Functions.

Feature Stored Procedure Function
Return Value Optional Must return a value
Usage Can be called independently Can be called in SQL statements
Side Effects Can modify data Should not modify data (ideally)
Transaction Control Allowed Limited

Answer:
Experienced testers validate parameters, output, error handling, and transaction handling for stored procedures and functions.


9. How do you perform Database Migration Testing?

Answer:

  1. Row Count Validation: Ensure total rows in source and target match.

  2. Data Validation: Compare sample records for accuracy.

  3. Schema Validation: Check constraints, indexes, triggers.

  4. Business Rules Validation: Ensure transformation logic applied correctly.

  5. Performance Testing: Validate queries run efficiently in the new system.

  6. Backup/Restore Testing: Verify rollback and recovery procedures.


10. What is database normalization? How do you validate it?

Answer:

  • Normalization: Process of organizing data to reduce redundancy and dependency.

  • Validation:

    1. Check tables for repeating groups (1NF).

    2. Ensure non-key attributes depend on the primary key (2NF).

    3. Ensure attributes are non-transitively dependent (3NF).

    4. Verify database changes don’t break relationships or constraints.


11. How do you test stored procedure performance?

Answer:

  • Use execution plans (EXPLAIN PLAN in Oracle, SHOW PLAN in SQL Server).

  • Monitor CPU, memory, and I/O usage during execution.

  • Execute with large datasets to check scalability.

  • Compare response times before and after optimization.


12. Explain your experience with ETL automation tools.

Answer:

  • Worked with Informatica, Talend, DataStage, or QuerySurge.

  • Automate ETL validation using SQL scripts or automation frameworks.

  • Validate data completeness, accuracy, and transformation rules automatically.

  • Schedule daily/weekly ETL regression tests.


13. How do you handle concurrent data issues?

Answer:

  • Test using multiple simultaneous transactions.

  • Validate locking mechanisms and isolation levels (READ COMMITTED, SERIALIZABLE).

  • Simulate deadlocks and long-running queries.

  • Ensure ACID compliance during concurrent updates.


14. How do you test database security?

Answer:

  • Verify user roles and permissions.

  • Ensure no unauthorized access to sensitive tables or views.

  • Test encryption of sensitive data.

  • Check audit logs and monitor database activity.

  • Validate SQL injection prevention and security best practices.


15. How do you validate indexing?

Answer:

  • Check if frequently queried columns are indexed.

  • Use EXPLAIN PLAN to ensure queries use indexes.

  • Validate impact on insert/update/delete performance.

  • Monitor index fragmentation and maintenance.


16. Explain your approach to regression testing in Database Testing.

Answer:

  • Maintain regression scripts for frequent data validation.

  • Automate SQL queries to check data integrity and business rules.

  • Validate stored procedures, triggers, and functions after changes.

  • Use test data management to ensure repeatable test scenarios.


17. How do you test database backup and recovery?

Answer:

  1. Perform full and incremental backups.

  2. Corrupt or delete some data.

  3. Restore from backup and validate data accuracy.

  4. Check database recovery times and integrity after crash scenarios.

  5. Test transaction rollback recovery.


18. How do you test complex queries?

Answer:

  • Validate joins, aggregations, subqueries, and group by conditions.

  • Compare results with manual calculations or sample datasets.

  • Test edge cases like NULLs, empty tables, and large data.

  • Monitor execution time and optimize queries if needed.


19. What is ETL testing and how do you ensure data quality?

Answer:

  • Validate extract, transform, and load processes.

  • Data quality checks:

    • Completeness (all rows loaded)

    • Accuracy (values transformed correctly)

    • Consistency (data matches source)

    • Conformity (formats and types correct)

  • Automation: SQL scripts, ETL validation tools, or custom scripts.


20. Scenario-Based Question: “If a report shows wrong data, how do you debug it?”

Answer:

  1. Check application query that generates the report.

  2. Validate source database values.

  3. Test ETL transformation logic if data comes from multiple sources.

  4. Verify joins, filters, and aggregations in the SQL.

  5. Compare report output vs database output.

  6. Identify root cause (application, ETL, database, or report logic).


21. How do you test data consistency across multiple environments (Dev, QA, Prod)?

Answer:

  • Compare row counts and sample data across environments.

  • Check schema consistency (tables, columns, indexes).

  • Verify stored procedures, triggers, and views exist and behave the same.

  • Validate ETL jobs and reports across environments.


22. What tools have you used for database testing?

Answer:

  • SQL Developer, TOAD, MySQL Workbench – Query validation and stored procedure testing.

  • QuerySurge, Informatica, Talend – ETL validation and automation.

  • Selenium + JDBC / Python scripts – End-to-end automation including DB validation.

  • LoadRunner / JMeter – Database performance testing.


23. Explain deadlocks and how you resolve them in testing.

Answer:

  • Deadlock: Two transactions wait for each other, causing a cycle.

  • Testing: Simulate multiple concurrent transactions with locks.

  • Resolution:

    • Use proper transaction isolation levels.

    • Commit transactions quickly.

    • Detect deadlocks using database monitoring tools and terminate one transaction.


24. How do you validate data after database upgrade or patching?

Answer:

  1. Compare row counts and sample data before and after upgrade.

  2. Validate stored procedures, triggers, and indexes.

  3. Execute critical queries and reports to check results.

  4. Test performance of queries and transactions.

  5. Validate security and permissions post-upgrade.


25. Scenario: “You see inconsistent data in child table after parent table update. How do you debug?”

Answer:

  1. Check referential integrity constraints (foreign key).

  2. Verify triggers and stored procedures affecting child table.

  3. Identify failed transactions or partial commits.

  4. Compare audit/log tables for changes.

  5. Fix by enforcing cascade updates or error handling in triggers/procedures.


 

26. What is a deadlock in a database, and how do you detect it?

Answer:
A deadlock occurs when two or more transactions wait indefinitely for resources held by each other.
Detection methods:

  • Use database monitoring tools (e.g., Oracle Enterprise Manager, SQL Server Profiler).

  • Query system tables (V$LOCK, sys.dm_tran_locks) to identify waiting transactions.

  • Enable deadlock trace or logging.
    Resolution:

  • Commit transactions quickly.

  • Apply proper locking and isolation strategies.

  • Use retry logic in applications.


27. What are orphan records, and how do you handle them?

Answer:

  • Orphan records: Child table rows with no corresponding parent.

  • Detection query example:

SELECT * 
FROM ChildTable c
LEFT JOIN ParentTable p ON c.ParentID = p.ID
WHERE p.ID IS NULL;
  • Handling:

    • Fix data manually or through ETL.

    • Enforce foreign key constraints.

    • Implement cascading updates/deletes if appropriate.


28. Explain how to validate data after ETL transformation.

Answer:

  • Compare source vs target data for row counts and values.

  • Validate transformation rules: aggregation, calculations, data type conversions.

  • Check data quality: nulls, duplicates, formatting errors.

  • Validate performance of ETL jobs under large volumes.

  • Use automation tools like QuerySurge, Informatica, Talend.


29. What is the difference between a primary key, unique key, and foreign key?

Key Type Primary Key Unique Key Foreign Key
Null Allowed No Yes (sometimes 1 null) Depends on constraint
Uniqueness Must be unique Must be unique Not necessarily unique
Purpose Identify row Prevent duplicates Maintain referential integrity
Number per table 1 Multiple Multiple

30. How do you validate stored procedures?

Answer:

  1. Check input and output parameters.

  2. Execute with valid and invalid inputs.

  3. Validate business rules implemented in procedure.

  4. Check transaction handling (COMMIT/ROLLBACK).

  5. Test performance for large data sets.


31. Explain how to test database performance under load.

Answer:

  • Identify heavy queries or frequently accessed tables.

  • Test using concurrent transactions to simulate multiple users.

  • Monitor CPU, memory, and I/O usage.

  • Optimize queries with indexes or query rewriting.

  • Use tools: LoadRunner, JMeter, SQL Profiler.


32. What are indexes, and how do you validate them?

Answer:

  • Index: Database structure to speed up query performance.
    Validation:

  1. Ensure indexes exist on frequently queried columns.

  2. Use EXPLAIN PLAN to check query execution paths.

  3. Check impact on INSERT/UPDATE/DELETE operations.

  4. Monitor index fragmentation and rebuild if necessary.


33. How do you test data consistency across multiple environments?

Answer:

  • Compare row counts for all tables across Dev, QA, and Prod.

  • Validate critical data values by sampling.

  • Ensure schema consistency: columns, constraints, indexes, triggers.

  • Execute stored procedures, views, and reports to verify consistent behavior.


34. Scenario: “Data is missing in a report. How do you debug?”

Answer:

  1. Check SQL query generating the report.

  2. Validate source database values.

  3. Verify ETL transformation logic if data comes from multiple sources.

  4. Check filters, joins, and aggregation in the report.

  5. Compare report output with database output.

  6. Identify root cause: query, ETL, or application logic.


35. What is data migration testing, and how do you validate it?

Answer:
Data migration testing ensures data moved from source to target is accurate and complete.
Validation steps:

  1. Compare row counts and key columns.

  2. Check data types and formats.

  3. Validate business rules and constraints.

  4. Test ETL jobs, stored procedures, and triggers.

  5. Validate performance and indexing in target.


36. How do you handle NULL values in testing?

Answer:

  • Identify mandatory columns that should not allow NULL.

  • Test queries, reports, and calculations with NULL values.

  • Validate default values applied for optional columns.

  • Check for application-level handling of NULL.


37. Explain scenario: “Transaction failed midway. How do you verify rollback?”

Answer:

  1. Create a multi-step transaction.

  2. Introduce an error in one operation.

  3. Verify previous steps are rolled back (no partial commits).

  4. Check database logs to confirm rollback.

  5. Validate data integrity and constraints remain intact.


38. How do you test triggers in a production database?

Answer:

  • Identify trigger type (BEFORE/AFTER, INSERT/UPDATE/DELETE).

  • Perform actions that activate the trigger.

  • Verify data modifications or audit logs.

  • Test negative scenarios (invalid inputs).

  • Monitor performance impact.


39. What is ETL automation, and how do you implement it?

Answer:

  • ETL automation involves automating data validation during ETL loads.

  • Use SQL scripts, Python scripts, or ETL testing tools like QuerySurge.

  • Validate row counts, transformation rules, and key columns automatically.

  • Schedule regression ETL tests for each load.


40. How do you test database security?

Answer:

  • Verify user roles and permissions.

  • Test restricted access to sensitive tables and columns.

  • Validate encryption and data masking.

  • Check audit logs for unauthorized activity.

  • Test SQL injection and vulnerabilities.


41. Explain scenario: “Child table has inconsistent data after parent table update.”

Answer:

  1. Verify foreign key constraints.

  2. Check triggers or stored procedures that update child tables.

  3. Identify partial or failed transactions.

  4. Analyze audit logs.

  5. Fix using cascading updates or proper error handling.


42. How do you validate reports generated from a database?

Answer:

  • Compare report data with database tables.

  • Validate aggregations, joins, and filters.

  • Test boundary cases, null values, and special characters.

  • Verify performance of report queries.

  • Automate regression using SQL scripts or testing tools.


43. How do you validate database after a patch or upgrade?

Answer:

  • Compare schema (tables, columns, constraints, indexes).

  • Verify stored procedures, functions, and triggers.

  • Test critical queries and reports.

  • Validate performance and security.

  • Check ETL jobs and automated scripts still work correctly.


44. What are materialized views, and how do you test them?

Answer:

  • Materialized view: Stores precomputed data physically.

  • Testing steps:

    1. Validate data accuracy with source tables.

    2. Test refresh schedules (complete/fast/force).

    3. Validate performance improvement over normal views.

    4. Check indexes on materialized views.


45. How do you handle large datasets during testing?

Answer:

  • Use sampling techniques for validation.

  • Perform batch processing for insert/update/delete.

  • Optimize queries with indexes and partitions.

  • Automate repetitive validation with scripts.

  • Test performance and scalability with large volumes.


46. Explain difference between UNION and UNION ALL.

Feature UNION UNION ALL
Duplicate rows Removed Retained
Performance Slower (duplicates removed) Faster
Use Case Unique combined results Combine all records

47. How do you test database triggers under concurrent transactions?

Answer:

  • Simulate multiple transactions updating or inserting data simultaneously.

  • Verify triggers fire correctly without data conflicts.

  • Check for deadlocks or locking issues.

  • Validate audit and logging triggers.


48. What is referential integrity, and how do you test it?

Answer:

  • Ensures foreign key values exist in parent table.
    Testing steps:

  1. Insert valid child records – should succeed.

  2. Insert invalid child records – should fail.

  3. Delete parent records – check cascade/restrict behavior.


49. Explain your approach to database regression testing.

Answer:

  • Maintain SQL scripts for validation of tables, views, and procedures.

  • Automate checks for row counts, transformations, and calculations.

  • Execute stored procedures and triggers after updates.

  • Validate ETL jobs and reports for consistent output.

  • Document expected vs actual results for each regression cycle.


50. Scenario: “A query is running very slow on production. How do you debug?”

Answer:

  1. Check query execution plan to identify bottlenecks.

  2. Verify indexes and partitions used in query.

  3. Analyze table size and joins.

  4. Check locking or deadlocks causing delays.

  5. Optimize query or add indexes, hints, or rewrite SQL.

  6. Test performance after changes before deploying.