Blog Article

Rohel Ahmed June 9, 2024 9:19 pm

TOP 125 SQL interview questions and answers for testers

TOP 125 SQL interview questions and answers for testers

#1. What is a database?

A database is an organized collection of structured data stored in a computer system. It allows for easy access to, management, and updating of information.

#2. What is a DBMS, and what types of DBMS do you know?

DBMS stands for database management system, a software system designed to maintain and access the database. It defines the rules of manipulation with data. There are two main types of DBMS: 
Relational database management system (RDBMS). It’s the most widely used DBMS model. An RDBMS allows storing of related data in multiple tables.

Non-relational database management system. It stores data in a non-tabular form. 

#3. What is the difference between primary and foreign keys?

A primary key is a column in a relational database table that is unique for each record. We use primary keys to identify the rows of a table.

A foreign key is a column in one table that refers to the primary key in another table. 

A table can have any number of columns with foreign keys but only one with primary keys. 

#4 What is a primary key? 

A primary key is a unique identifier for a row in a table. It ensures that each row can be uniquely identified and helps maintain data integrity.

#5 What is a foreign key? 

A foreign key is a field in a table that refers to the primary key of another table. It establishes a relationship between two tables, ensuring referential integrity.

#6. Name a few popular database management systems.

Oracle, MySQL, Microsoft SQL Server, PostgreSQL, MongoDB, and Microsoft Access.

#7. What is SQL?

SQL stands for structured query language. It’s used to access and manipulate relational databases. For example, we can create and delete tables or insert and update data using SQL.

#8 What is SQL and its significance in software testing? 

SQL (Structured Query Language) is a programming language used to manage and manipulate relational databases. Testers often use SQL to query databases, validate data, and perform data-related tests.

#9. What do DDL and DML stand for?

DDL stands for data definition language. It includes SQL statements that define the database structure: CREATE, ALTER, and DROP.

DML stands for data manipulation language. It includes SQL statements that are used to manipulate the data records: INSERT, UPDATE, DELETE, etc. 

#10. What are SQL constraints?

SQL constraints are rules that enforce certain restrictions while inserting, deleting, or updating data. Here are a couple of examples:

·         NOT NULL: Specifies that a column must always have a value. 

·         UNIQUE: Ensures there are no duplicate values stored in a particular column.

#11. What are the different clauses used in SQL?

Clauses in SQL are built-in functions used to retrieve data from the database. For example:

·         WHERE

·         HAVING

·         AND

·         OR

·         GROUP BY

·         ORDER BY

#12. Describe what NULL means in SQL.

In SQL, NULL means "none." It indicates that a value for a particular field is missing. Any column in the table can be set to allow or not allow a NULL value.

#13. What possible values can be stored in a BOOLEAN data field?

Boolean values can be either True or False.

SQL Query Questions

#14. How do you write a basic SQL query to retrieve all data from a table?

SELECT * FROM table_name

#15. What is a subquery, and how is it used in SQL?

A subquery is an SQL query nested inside another query. The subquery is executed first, and the outer query uses its results. Subqueries are used for filtering, comparing, calculating, or modifying data.

#16. How do you join two tables in SQL?

In SQL, we use the JOIN statement to join two tables together. JOIN allows us to combine rows from two or more tables based on a related column or set of columns.

#17. What types of joins do you know?

·         INNER JOIN: returns records that have matching values in both tables

·         OUTER JOIN: returns matched and unmatched values

·         LEFT JOIN: returns all rows from the left table and the matching rows from the right table

·         RIGHT JOIN: returns all rows from the right table and the matching records from the left table

#18. How do you use SQL to update data in the database?

To update data, we use an UPDATE statement. For example, let's say we have a table called "Customers" with columns "customer_id," "name," "email," and "phone." To update a customer's email address based on their customer ID, we would use the following SQL statement:

UPDATE Customers 

SET email = 'new_email@example.com' 

WHERE customer_id = 123;

#19. How can you avoid duplicate records in a query?

We use the DISTINCT keyword to avoid duplicate records in an SQL query. For example, let's say we have a table called "Orders" with columns "order_id," "customer_id," "product_name," and "price." If we want to select all unique products from the table, we would use the following SQL statement:

SELECT DISTINCT product_name 

FROM Orders;

#20. What is the difference between DELETE, TRUNCATE, and DROP commands?

DELETE is used to delete some or all rows from the table. It can be rolled back.

TRUNCATE is used to delete all rows from the table. It can't be rolled back.

DROP removes a table from the database. It can't be rolled back.

#21. What is the difference between the HAVING and WHERE clauses?

The WHERE clause is used to filter rows from the result set before any grouping or aggregation takes place.

The HAVING clause is used to filter data that meets particular criteria specified by the aggregate functions. It is used in association with the GROUP BY clause. 

#22. What are aggregate functions in SQL?

Aggregate functions in SQL perform calculations on a set of values and return a single value. The most commonly used aggregate functions in SQL are:

·         COUNT: returns the number of rows in a group or a table

·         SUM: returns the sum of the values in a group or a table

·         AVG: returns the average of the values in a group or a table

·         MAX: returns the maximum value in a group or a table

·         MIN: returns the minimum value in a group or a table

#23. Describe SQL comments.

SQL comments are lines of text that we add to an SQL query to provide information to other users. The SQL engine ignores comments, so they don't affect the execution of our queries. Single-line comments start with two dashes (--) and end at the end of the line. Multi-line comments begin with a slash and asterisk (/*) and end with an asterisk and slash (*/).

SQL Testing Questions

#24. What is database testing?

Database testing is a type of testing that verifies the functionality, performance, and reliability of a database. It checks schema, tables, and triggers. Database testing involves various tests: structural, functional, performance, data integrity, security, etc.

#25. What is the difference between GUI testing and database testing?

During user interface testing, a QA engineer checks the items that users can see and interact with. They test text boxes, dropdown menus, buttons, and so on. To perform this type of testing, testers need a thorough understanding of the business requirements for a particular application. 

During database testing, a QA engineer focuses on things hidden from users: storage procedures, tables, indexes, etc. To perform this type of testing, testers need a solid knowledge of database concepts and familiarity with SQL queries.

#26. How do you test a database manually?

During manual database testing, we use SQL to compare data at the back end with expected results. For example, we can update some records via GUI and then retrieve the data from the database to check if this update was recorded correctly. 

#27. How did you use SQL at your previous job?

I used it when working with certain types of test cases. For example: 

·         Add a user and check in the database if a user was created

·         Remove a user and check if they were removed from the database

·         Update the user's information and check if it was updated in the database

#28. How would you use SQL to verify that data has been inserted correctly into the database?

I would use the SELECT statement to retrieve the data from the database and verify that the returned values match the expected results. 

#29. How would you test for NULL values?

NULL indicates that a field has no value. Therefore, we cannot use comparison operators like < or >. Instead, we use IS NULL. For example:

SELECT * FROM table_name WHERE column_name IS NULL;

#30. How would you use SQL to identify duplicate records in a table?

To identify duplicate records in a table, I would use the GROUP BY clause and COUNT function in the HAVING clause to check if any of the groups have more than one entry. For example, to check for duplicate order IDs in the OrderID column of the Orders table, I would use the following query:

SELECT OrderID, COUNT(OrderID)

FROM Orders

GROUP BY OrderID

HAVING COUNT(OrderID) > 1

#31. How can we check whether a trigger is fired?

We can check the audit log to see if a trigger was fired or not. Alternatively, we can create test data that triggers the trigger and verify whether the expected actions have been taken. For example, if the trigger inserts a record into a table, we can check whether the record has been inserted.

 

#32 What are the different types of SQL statements? 

SQL statements can be classified into four main types:

·         Data Manipulation Language (DML): Used to manipulate data in the database (e.g., SELECT, INSERT, UPDATE, DELETE).

·         Data Definition Language (DDL): Used to define and modify database structures (e.g., CREATE, ALTER, DROP).

·         Data Control Language (DCL): Used to control access and permissions on the database (e.g., GRANT, REVOKE).

·         Transaction Control Language (TCL): Used to manage transactions in the database (e.g., COMMIT, ROLLBACK).

 

#33 What is normalization? 

Normalization is the process of organizing data in a database to reduce redundancy and improve data integrity. It involves breaking down tables into smaller, more manageable structures.

#34 What is a stored procedure? 

A stored procedure is a set of SQL statements that are stored and executed on the database server. It can be called and executed multiple times, reducing network traffic and improving performance.

#35. What is a view in SQL? 

A view is a virtual table derived from one or more tables. It does not store data but presents the data in a predefined manner, simplifying complex queries.

#36. What is the difference between UNION and UNION ALL? 

UNION combines the result sets of two or more SELECT statements, removing duplicate rows. UNION ALL also combines result sets but includes all rows, including duplicates.

#37. Who should learn SQL?

• Database Developers

• Database Testers

• Database Administrators



#38. What are the Usages of SQL?

•    Creating new databases
•    Creating new tables in a database
•    Inserting records in a database
•    Updating records in a database
•    Deleting records from a database
•    Retrieving data from a database
•    Executing queries against a database
•    Creating stored procedures in a database
•    Creating views in a database
•    Setting permissions on tables, procedures, and views
Etc… 

#39. What are the sub sets of SQL?
 
•    Data Definition Language
•    Data Manipulation Language
•    Data Control Language

#40. What is Data Definition Language?
 
Data Definition Language (DDL) allows us to create, alter, and delete database objects such as schemas, tables, views, sequences, catalogs, indexes, and aliases.

#41. What is Data Manipulation Language?
 
DML is a language which enables users to access and manipulate data. 

Data Manipulation Language is used to Perform below Operations:
•    Insertion of data into the database 
•    Retrieval of data from the database 
•    Updating data in the database 
•    Deletion of data in the database 


#42. What is Data Control Language?
 
Data Control Language (DCL) allows us to control access to the database. 'DCL' commands include- 
'GRANT' to allow specific users to perform specified tasks 
'REVOKE' to cancel previously denied or granted permissions

#43. What is an index? 

An index is a database structure that improves the speed of data retrieval operations. It allows faster searching, sorting, and filtering of data.

#44. What is the difference between a clustered and a non-clustered index? 

A clustered index determines the physical order of data rows in a table, while a non-clustered index is a separate structure that stores a copy of the indexed columns along with a pointer to the actual row.

#46. What is the purpose of the GROUP BY clause? 

The GROUP BY clause is used to group rows based on one or more columns. It is often used with aggregate functions like COUNT, SUM, AVG, etc., to perform calculations on groups of data.

#47. What is a self-join? 

A self-join is a join operation where a table is joined with itself. It is useful when there is a need to compare rows within the same table.

#48. Explain the difference between the WHERE and HAVING clauses. 

The WHERE clause is used to filter rows before grouping, while the HAVING clause is used to filter groups after grouping.

#49. What is the purpose of the EXISTS operator? 

The EXISTS operator is used to check the existence of rows returned by a subquery. It returns true if the subquery returns any rows; otherwise, it returns false.

#50. What is the ACID property in database systems? 

ACID stands for Atomicity, Consistency, Isolation, and Durability. It defines the properties that ensure reliable processing of database transactions.

#51. What is DBMS?

> A database management system, or DBMS, is software designed to assist in maintaining and utilizing large collection of data. 

> The alternative to using a DBMS is to store the data in files and write application-specific code to manage it.

Using a DBMS to manage data has many advantages like:

•    Data independence
•    Efficient data access
•    Data integrity and security
•    Data administration
•    Concurrent access and data recovery 

#52. What is MS Access?
 
MS Access was launched in 1992 by Microsoft Corporation as part of MS Office.
Microsoft Access is entry-level database management software. It is not only an inexpensive but also powerful database for small-scale projects.
MS Access uses the Jet database engine which utilizes a specific SQL language dialect (sometimes referred to as Jet SQL).
MS Access comes with the professional edition of MS Office package. MS Access is user friendly database management system. 

#53. What is Oracle?

Oracle is a relational database management system developed by 'Oracle Corporation and launched in 1977.
Oracle supports all major Operating systems includes, MS Windows. NetWare, UnixWare, OS/2 and most UNIX flavors. 

#54. What is MS SQL Server?
 
MS SQL Server is a Relational Database Management System developed by Microsoft Inc. Its primary query languages are T-SQL and ANSI SQL. 

#55. What is Sybase?

Sybase is a computer software company , their primary product is Sybase DBMS, which is a relational database management system based upon structured query language. 

#56. What is MySQL?
 
MySQL is open source Database Management System, developed by Swedish company MySQL AB. 
MySQL Supports many different platforms including Microsoft Windows, the major Linux distributions, UNIX, and Mac OS X.
MySQL has free and paid versions, depending on its usage (non-commercial/commercial) and features. MySQL comes with a very fast, multi-threaded, multi-user, and robust SQL database server.

#57. What is DB2? 

DB2 is the short name used for DATABASE 2. It is relational database product developed by IBM. in 1983 

#58. What is DB/400?

It is one of the flavors of IBM DB2 

#59. What are the categories of operators available in SQL?
 
•    Arithmetic operators
•    Comparison operators
•    Logical operators
 

#60. What are Arithmetic operators in SQL? 

Operator

Description

+ (Addition )

Adds values

- (Subtraction)

Subtracts Right side value from Left side value

* (Multiplication)

Multiplies values on either side of the operator

/ (Division)

Divides left hand operand by right hand operand

% (Modulus)

Divides left hand operand by right hand operand and returns remainder



#61. What are Comparison operators in SQL?

For example x = 1, y= 2

Operator    Example
=             (x = y) is False
!=            (x != y) is True. 
<>           (x <> y) is true. 
>             (x > y) is False
<             (x < y) is True        
>=           (x >= y) is False
<=           (x <= y) is True
!<            (x !< y) is False
!>            (x !> y) is True. 

Note: Comparison Operators return Logical Results

#62. What are Logical operators in SQL?  

Operator    Description 
--------        -----------

NOT           Returns TRUE if the following condition is FALSE. Returns FALSE if  it is TRUE.  
AND           Returns TRUE if both component conditions are TRUE. Returns FALSE if either is FALSE 
OR            Returns TRUE if either component condition is TRUE. Returns FALSE if both are FALSE.

#63. What is a Data Relationship and What are they?

Database Relationship is the connection between the tables in a database. There are 4 types of relationships, and they are:

•    One to One Relationship
•    One to Many Relationship
•    Many to One Relationship
•    Many to Many Relationship

#64.  What are Important Data Types in SQL?

 

Data Type

Syntax

character

char(x)

integer

integer

numeric

numeric(p,s)

decimal

decimal(p,s)

float

float(p)

date

date

time

time

character varying

varchar2(x)

bit

bit(x)

real

real

smallint

smallint

 


#65.  How to Create a Database?

The SQL CREATE DATABASE statement is used to create new SQL database.

Syntax:

CREATE DATABASE DatabaseName;

Example: 

SQL> CREATE DATABASE TestData;

#66.  How to delete a Database?

Using DROP DATABASE statement we can delete any existing Database

Syntax:

DROP DATABASE DatabaseName;

Example:

SQL> DROP DATABASE TestData;

#67.  How to Select a Database?

USE statement is used to select any existing database in SQL

Syntax:

USE DatabaseName;

Example:

SQL> USE TestData;

#68.  How to view all existing Databases list?

SQL> SHOW DATABASES;

#69.  How to create a Table?


CREATE TABLE table_name(
   column1 datatype,
   column2 datatype,
   column3 datatype,
   .....
   columnN datatype,
   PRIMARY KEY( one or more columns )
);

#70.  How to delete a Table?

Using Drop Table we can delete a Table

Syntax:

DROP TABLE table_name;

#71.  How to add new record into a Table?

Using INSERT INTO statement, we can insert new rows

Syntax:

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

#72.  How to fetch data from a Database Table?
 
Using SELECT Statement, we can fetch data from a Database Table

Syntax:

SELECT column1, column2, columnN FROM table_name;

Or

SELECT * FROM table_name;

#73.  Explain about IN Operator?

The IN operator implements comparison to a list of values, that is, it tests whether a value matches any value in a list of values. IN comparisons have the following general format:
value-1 [NOT] IN ( value-2 [, value-3] ... )
This comparison tests if value-1 matches value-2 or matches value-3, and so on. It is equivalent to the following logical predicate:
value-1 = value-2 [ OR value-1 = value-3 ] ...

#74.  Explain about FROM Clause in SQL?

The FROM clause always follows the SELECT clause. It lists the tables accessed by the query. For example,
SELECT * FROM x
When the From List contains multiple tables, commas separate the table names. For example,
SELECT sp.*, city
FROM sp, x
WHERE sp.sno=x.sno
When the From List has multiple tables, they must be joined together.

#75.  What is the parameter substitution symbol used with INSERT INTO command?


The parameter substitution symbol used with INSERT INTO command is &.

#76.  What are the various uses of database triggers?

Database triggers can be used to enforce business rules, to maintain derived values and perform value-based auditing. 

#77.  What is a event handler in sql?

An event handler is a routine that is written to respond to a particular event.

#78.  What are two methods of retrieving SQL?

The two methods of retrieving SQL are 
1-Select
2-using Cursor.

#79.  What is a synonym? How is it used?

A synonym is used to reference a table or view by another name. The other name can then be written in the application code pointing to test tables in the development stage and to production entities when the code is migrated. The synonym is linked to the AUTHID that created it. 

#80.  What is referential integrity?
 
Referential integrity refers to the consistency that must be maintained between primary and foreign keys, i.e. every foreign key value must have a corresponding primary key value.

#81.  Explain the EXPLAIN statement?
 
The explain statement provides information about the optimizer's choice of access path of the SQL.

#82.  How is the SUBSTR keyword used in SQL?

 
SUBSTR is used for string manipulation with column name, first position and string length used as arguments. E.g. SUBSTR (NAME, 1 3) refers to the first three characters in the column NAME.

#83.  What is the difference between group by and order by?
 
Group by controls the presentation of the rows, order by controls the presentation of the columns for the results of the SELECT statement.

#84.  What is a subselect? Is it different from a nested select?
 
A subselect is a select which works in conjunction with another select. A nested select is a kind of subselect where the inner select passes to the where criteria for the outer select.

#85.  What is the use of CASCADE CONSTRAINTS?
 
When this clause is used with the DROP command, a parent table can be dropped even when a child table exists.

#86.  How do you prevent output from coming to the screen?
 
The SET option TERMOUT controls output to the screen. Setting TERMOUT OFF turns off screen output. This option can be shortened to TERM.
 
#87.  Can Primary key is a Foreign Key on the same table?

Yes, Primary key is a Foreign Key on the same table.

#88.  How do you execute a host operating system command from within SQL?
 
By use of the exclamation point “!” (in UNIX and some other OS) or the HOST (HO) command.

#89. What is a Cartesian product?
 
A Cartesian product is the result of an unrestricted join of two or more tables. The result set of a three table Cartesian product will have x * y * z number of rows where x, y, z correspond to the number of rows in each table involved in the join.

#90.  How can variables be passed to a SQL routine?

 
By use of the & symbol. For passing in variables the numbers 1-8 can be used (&1, &2,...,&8) to pass the values after the command into the SQL PLUS session. To be prompted for a specific variable, place the ampersanded variable in the code itself: “select * from dba_tables where owner=&owner_name;” . Use of double ampersands tells SQLPLUS to resubstitute the value for each subsequent use of the variable, a single ampersand will cause a reprompt for the value unless an ACCEPT statement is used to get the value from the user.

#91.  What command is used to get back the privileges offered by the GRANT command?
 
Revoke command is used to get back the privileges offered by the GRANT command.

#92. What are the advantages of procedures?

Advantages of procedures:

• Loaded once and used many times.
• Performance better coz all SQL statements are sent in one go from the application to the database.
• Security (no object privileges are given directly).
• Invoker's rights possible.
• Data integrity, productivity.

#93.  What is Parsing?
 
Parsing checks syntax, checks privileges, and allocating Private SQL Area.

#94.  What is Cursor?

Name or handle to a private SQL area where Oracle parses and fetches query results.

#95.  Is SQL supports Conditional and Loop Statements?

No Basically SQL is a Command based Language, not a procedural  language, but it has Operators and built-in Functions.


#96.  What are most important DDL Commands in SQL?


CREATE TABLE - creates a new database table
ALTER TABLE - alters (changes) a database table
DROP TABLE - deletes a database table
CREATE INDEX - creates an index (search key)
DROP INDEX - deletes an index 

 

#97. What are the Operators used in SELECT statements?


= Equal

<> or != Not equal

> Greater than

< Less than

>= Greater than or equal

<= Less than or equal

BETWEEN Between an inclusive range LIKE Search for a pattern


#98.  How to  INSERT Values into Tables?

INSERT INTO table_name VALUES (value1, value2,....)

INSERT INTO table_name (column1, column2,...) VALUES (value1, value2,....)

#99.  How to Update a Column Name?

UPDATE table_name SET column_name = new_value WHERE column_name = some_value

 

#100.  How to Delete Columns, Rows?


Delete a particular column:

DELETE FROM table_name WHERE column_name = some_value

Delete All Rows:

DELETE FROM table_name or DELETE * FROM table_name


#101. Give an usage for BETWEEN ... AND?


SELECT column_name FROM table_name WHERE column_name BETWEEN value1 AND value2 The values can be numbers, text, or dates.

#102.  What is the use of CASCADE CONSTRAINTS?


When this clause is used with the DROP command, a parent table can be dropped even when a child table exists.

#103.  Why does the following command give a compilation error?


DROP TABLE &TABLE NAME;

Variable names should start with an alphabet. Here the table name starts with an '&' symbol.

#104.  Which system tables contain information on privileges granted and privileges obtained?


USER_TAB_PRIVS_MADE, USER_TAB_PRIVS_RECD 

#105.  Which system table contains information on constraints on all the tables created?obtained?


USER_CONSTRAINTS. 


#106.  State true or false. EXISTS, SOME, ANY are operators in SQL?


True.


#107.  What does the following query do?


SELECT SAL + NVL(COMM,0) FROM EMP;?

This displays the total salary of all employees. The null values in the commission column will be replaced by 0 and added to salary.

 

#108.  What is the advantage of specifying WITH GRANT OPTION in the GRANT command?


The privilege receiver can further grant the privileges he/she has obtained from the owner to any other user.

 

#109.  Which command executes the contents of a specified file?


START or @. 

#110.  Which command displays the SQL command in the SQL buffer, and then executes it?


RUN. 

#111.  What command is used to get back the privileges offered by the GRANT command?


REVOKE. 

#112.  Which date function is used to find the difference between two dates?


MONTHS_BETWEEN. 

#113.  What operator performs pattern matching?


LIKE operator. 

#114.  What is the use of the DROP option in the ALTER TABLE command?


It is used to drop constraints specified on the table. 

#115.  What operator tests column for the absence of data?


IS NULL operator. 

#116.  What are the privileges that can be granted on a table by a user to others?


Insert, update, delete, select, references, index, execute, alter, all. 

#117.  Which function is used to find the largest integer less than or equal to a specific value?


FLOOR. 

#118.  Which is the subset of SQL commands used to manipulate Oracle Database structures, including tables?


Data Definition Language (DDL).

#119.  What is the use of DESC in SQL?


DESC has two purposes. It is used to describe a schema as well as to retrieve rows from table in descending order.

Explanation :

The query SELECT * FROM EMP ORDER BY ENAME DESC will display the output sorted on ENAME in descending order.

#120.  What command is used to create a table by copying the structure of another table?


CREATE TABLE .. AS SELECTcommand

Explanation:

To copy only the structure, the WHERE clause of the SELECT command should contain a FALSE statement as in the following.

CREATE TABLE NEWTABLE AS SELECT * FROM EXISTINGTABLE WHERE 1=2;

If the WHERE condition is true, then all the rows or rows satisfying the condition will be copied to the new table.


#121.  What is the output of the following query SELECT TRUNC(1234.5678,-2) FROM DUAL;?


1200. 

#122.  What are the wildcards used for pattern matching.?


_ for single character substitution
% for multi-character substitution.


#123.  What's an SQL injection?


SQL Injection is when form data contains an SQL escape sequence and injects a new SQL query to be run.

#124.  What is difference between TRUNCATE & DELETE?


TRUNCATE commits after deleting entire table i.e., cannot be rolled back. Database triggers do not fire on TRUNCATE

DELETE allows the filtered deletion. Deleted records can be rolled back or committed. Database triggers fire on DELETE.

#125.  What is a join? Explain the different types of joins?


Join is a query, which retrieves related columns or rows from multiple tables.


Self Join - Joining the table with itself.

Equi Join - Joining two tables by equating two common columns. Non-Equi Join - Joining two tables by equating two common columns.

Outer Join - Joining two tables in such a way that query can also retrieve rows that do not have corresponding join value in the other table.

 

#126.  What is the sub-query?


Sub-query is a query whose return values are used in filtering conditions of the main query.

#127.  What is correlated sub-query?


Correlated sub-query is a sub-query, which has reference to the main query.

#128.  Explain CONNECT BY PRIOR?


Retrieves rows in hierarchical order eg. select empno, ename from emp where. 

#129.  Difference between SUBSTR and INSTR?


INSTR (String1, String2 (n, (m)), 

INSTR returns the position of the m-th occurrence of the string 2 in string1. The search begins from nth position of string1. 

SUBSTR (String1 n, m) 

SUBSTR returns a character string of size m in string1, starting from n-th position of string1. 

#130.  Explain UNION, MINUS, UNION ALL and INTERSECT?


INTERSECT - returns all distinct rows selected by both queries.

MINUS - returns all distinct rows selected by the first query but not by the second.

UNION - returns all distinct rows selected by either query

UNION ALL - returns all rows selected by either query,including all duplicates.

#131.  What is ROWID?


ROWID is a pseudo column attached to each row of a table. It is 18 characters long, blockno, rownumber are the components of ROWID.

#132.  What is the fastest way of accessing a row in a table?


Using ROWID. CONSTRAINTS 

#133.  What is an integrity constraint?


Integrity constraint is a rule that restricts values to a column in a table.

#134.  What is referential integrity constraint?


Maintaining data integrity through a set of rules that restrict the values of one or more columns of the tables based on the values of primary key or unique key of the referenced table.

#135. Explain the difference between a full backup and an incremental backup. 

A full backup copies all data in a database, while an incremental backup only copies the changes made since the last backup. Incremental backups are faster but require more effort to restore.

#136. What is a deadlock? 

A deadlock is a situation where two or more transactions are waiting for each other to release resources, resulting in a permanent state of inactivity. It can lead to a system freeze or deadlock resolution by a database management system.

#137. How can you optimize a SQL query? 

SQL query optimization can be achieved through various techniques like creating indexes, minimizing the use of subqueries, using efficient join methods, and retrieving only the necessary columns.

#138. What is data integrity? 

Data integrity ensures the accuracy, consistency, and reliability of data. It can be enforced through primary key constraints, foreign key constraints, and data validation rules.

Remember, these questions and answers serve as a guide for interview preparation, but it’s always beneficial to have a solid understanding of SQL concepts and be able to explain them in your own words. Good luck with your interviews!

#139. How would you approach writing test cases for database testing?

·         I would start by analyzing requirements to understand the database's expected behavior better. 

·         Then, I would identify the test scenarios that need to be tested.

·         Next, I would create test cases based on the test scenarios. I would include a description of the test case, test inputs, expected outputs, and test execution steps.

#140. How to find the 3rd highest marks from the Student table?

SELECT TOP 3 marks FROM (SELECT DISTINCT TOP 3 marks FROM student ORDER BY marks DESC) a ORDER BY marks

#141. What is the function of a foreign key in a database?

A foreign key is used to define a relationship between the parent and child table connected by columns. The foreign key is a constraint that ensures that the values of the child table appear in the parent table. The foreign key of one table is the primary key of the other, and a table can have several foreign keys. For example:

student {ID, Name, Age, Contact, Gender, Add}

teacher{Teach_ID, Name, ID}

Here, ID is the foreign key for the teacher table.