30.1 C
Delhi
Thursday, August 11, 2022
Home > Interview TipsCommon SQL Interview Questions and Answers

Common SQL Interview Questions and Answers

As an interview is the most prominent screening process in job selections, mastering the anticipated questions and appearing prepared for the future job role is of utmost importance. In any programming language, few such functions and syntaxes are almost always required to be known. If not, then it certainly is not going to leave a good impression on the interviewer.

SQL Interview Questions for Testers

  • What is SQL?
  • Creation of Table in SQL server
  • What is Normalization in SQL?
  • What are the types of Joins in SQL?

1. What is SQL?


SQL stands for Structured Query Language, also known as SEQUEL.
It was developed by two IBM researchers, Raymond Boyce and Donald Chamberlain, in the 1920s.
SQL is the most widely used language in Relational Database Management Systems (RDBMS). It is used to read, write, and execute data from a particular database. It is a basic query language used to retrieve, store and manipulate data found in relational databases, others being Oracle, MySQL, MS Access, etc.
SQL queries work through a series of commands or statements that we will try to understand later in this article.

2. Creating a Table in SQL server

It can be done by opting for CREATE TABLE from SELECT or
CREATE TABLE, followed by the table name, Data to be organized for example Details of the Employees or
by using CREATE TABLE by applying FOREIGN KEY

3. What is Database Normalization in SQL?


It is designing and organizing data in a table. RDBMS data is represented through fields in a table.
Data normalization involves
Eliminating redundancy and duplication of data.
Ensures relationships between data make sense. This ensures optimal utilization of space and logic in database designing.
It consists of guidelines and formats that help in database creation. It is like a layout of a building before construction is carried out. Normal forms require the database to conform to at least three normal forms. Going through the fourth or fifth normal form is optional.
The first normal Form ensures
defining data and sorting of data into columns
That there is no data repetition and,
Defining primary key

IDNAMECUST. ADDRESSPRODUCTS PURCHASED
14SUHASCOSMOS LOUNGENIKE T-SHIRT
14SUHASCOSMOS LOUNGESHOES 
14SUHASCOSMOS LOUNGESOCKS

Here there is a single customer with multiple orders, so to avoid repetition, we assign a primary key, there will be two sets of tables. So, the data will look something like this:

IDNAMECUST. ADDRESS
14SUHASCOSMOS LOUNGE
IDPRODUCT PURCHASED
14NIKE T-SHIRT
14SHOES
14 SOCKS

Second Normal Form 2NF

It ensures that all the guidelines of the first normal are met, and there are no column dependencies on the primary key.

Third Normal Form 3NF

Data should be in the second normal form.

  • Here attribute is functionally dependent on an attribute other than the primary key whose value is only indirectly determined by the primary key.
  • The creation of a separate table containing the attribute and the fields that are functionally dependent on it is required.

Normalization features in almost every list of SQL interview questions for testers.

4. What are the different types of Joins in SQL servers?

There are four types of joins in SQL.

A.Inner Join: Shows all rows when at least one match is found in BOTH the tables.

B.Left Join: Shows all rows from the left table and rows that match from the right table.

C.Right Join: Vice versa of Left join

D.Full Join: Shows all rows when at least a single match in any of the tables.

5. What is DBMS (Database Management Systems)?


It is a collection of programs that enable users to create, access, and manipulate databases.


6. What is RDBMS (Relational Database Management Systems)?


It is the base for SQL and all others like Oracle, MySQL, Microsoft Access, etc.
The database contains files, while RDBMS consists of Tables. Relational Databases have some degree of relation between them so that they are related and can be used to find coherence in their presentation.
A database is a systematic collection of data structured and organized in a meaningful way.
Management systems are tools to interpret this structured and organized data.
So, when appearing for SQL server interviews, a tester should know these differences.

7. What are SQL Commands?


DDL – Data Definition Language
CREATE: Creates a new or a view of a table,
ALTER: as the name suggests, alters an existing database object.
DROP: Deletes a table, or other objects in the database.
DML – Data Manipulation Language
INSERT: Creates a record
UPDATE: Modifies record
DELETE: Deletes record
DCL – Data Control Language
GRANT: Gives the user a privilege
REVOKE: Takes that privilege away
DQL – Data Query Language
SELECT: Retrieves records from one or more datasets

8. What are Constraints in SQL?

Constraints are certain rules applied on data columns or the entire table. These are used so that only selected data can be fed into the table to maintain accuracy and dependability on data so given. Constraints can be selectively applied to columns or the entire table. For example, when asked in a SQL server interview, a tester can enumerate the following commonly used constraints:

NOT NULL Constraint: It is used to ensure NULL value is not returned in the column.
DEFAULT Constraint: When no values are specified, it returns the default value.
UNIQUE Constraint: Ensures uniqueness of values in a column so that each value is different.
CHECK Constraint: ensures that all values in a column satisfy certain conditions.
INDEX: Use to create and search databases quickly.
PRIMARY Key: Uniquely recognizes each row/record in a database table.
FOREIGN Key: Uniquely shows a row/record in another database table.

9. What is Primary Key in SQL?

It contains unique values. It helps uniquely identify rows or columns. One must ensure no null values in this column, or the whole reference will be lost. A table can have only one primary key with single or multiple fields.
It is one of the important features of Database management systems.

10. What are Views in SQL?

There are two types of Views, Simple and Complex
A simple view can filter or show rows and columns selectively.
A complex view can be a complex query consisting of subqueries, joints, etc.

SQL Queries interview questions for testers

11. What is an Index?

In Database management systems, indexes act as references for speedy access of data. One can accordingly use Create Index, Alter Index, and Drop Index commands in SQL.

Just like there are indexes in books for quick access, indexes perform the same role in SQL databases. 

There are two types of indexes:

  • Clustered
  • Non- Clustered
Clustered IndexNon- Clustered Index
This will arrange the rows physically in the memory in sorted orderThis will not arrange the rows physically in the memory in sorted order.
This will fast in searching for the range of values.This will be fast in searching for the values that are not in the range.
Index for a table.You can create a maximum of 999 non clustered indexes for a table.
The leaf node of the 3 tier of the clustered index contains, contains table data.Leaf nodes of b-tree of the non-clustered index contain pointers to get the contains pointers to get that contains two table data, and not the table data directly.

12. What are Union and Union All?

The Union function combines data from different table databases without selecting duplicate values. Whereas a Union All function aggregates data from multiple datasets without excluding duplicate values.

Union All has better efficiency in displaying relevant data without much distortion as compared with Union operator.

13. Difference between Delete, Truncate, and Drop commands in SQL?

  • Delete command eliminates some specified rows or all rows from the table database
  • Truncate command eliminates all rows and the action is irreversible.
  • Drop command eliminates the entire table from the database and along with it all functions, triggers, rows, and references are removed as well.

It is one of the most commonly asked questions in SQL database query interviews.

14. What are transactions and Controls in SQL?

The transaction is logical tasks performed on a database to retrieve certain results. Operations performed like Creating, updating, deleting records in the database comes from transactions.

They can be called SQL queries run on a database to gain results.

There are 4 transaction controls such as


A.COMMIT: to save all changes made through the transaction
B. ROLLBACK: is used to reverse the changes made during transactions
C. SET TRANSACTION: used to name a particular transaction
D.SAVEPOINT: It specifies the point of reversal from where the transaction is to be rolled back.

15. Properties of a Transaction in SQL queries or an ACID Test?

The ACID test or properties determine the characteristics of a transactions.
They are:
Atomicity
Consistency
Isolation
Durability

16. Difference between Stored procedure and User-defined Function in a Database management system?


Stored procedures are codes that can be put to use whenever called upon. They are reusable in nature. It is compiled and its code is stored for easy access for the performance of repetitive tasks.
User-defined functions are compiled new each time. They can show only a single value or a table. Functions must return value, but a procedure can return any number of values or even a zero.

17. Difference between ISNULL and COALESCE FUNCTIONS

Both are used to replace Null with a value defined by the user.
In ISNULL function one has to be specific with replacement value, with argument restriction of two.
Coalesce returns the first non-null value. Here there is no argument restriction except they should belong to the same datatype.

There syntax is as follows:
ISNULL (check_exp, change value)
COALESCE (expression [ ,…n] )

One ought to know this in SQL server interview for testers

18. What is Database Testing in SQL?

It is checking data for its integrity i.e., how efficiently one can extract the information required from the given dataset.
It is testing Data for its Integrity, performance, validity, and working of different functions, operators, etc.

19. Explain steps in Database testing

Why a database is tested?

It is to maintain consistency in the database. Therefore, when the users in the front end do any changes, the same should reflect in the backend where the database is maintained in DBMS.
This ensures data integrity. This is the reason the Database is to be tested on the following parameters:
Data mapping
ACID property test
Check Data Integrity
What is to be tested?
Transactions
Schemas
Field Constraints
Triggers
Procedures that are user-defined functions

20. What are Table Aliases in SQL database?


They are temporary names given to columns or tables to increase their readability and reduce ambiguity. They are used when table names are very long and when a query involves two or more tables. It doesn’t alter the original name of the table in the database as such.

21. Explain BCNF


BCNF stands for Boyce- Codd Normal Form
It is one of the normalization techniques and is based on the concept of Determinants. A determinant is an attribute that determines the attributes of some other functionally dependent on it.
BCNF applies only if every determinant is a Candidate key.

22. What are SQL Syntaxes?

All the SQL statements begin with any keywords like SELECT, INSERT, UPDATE, DELETE, ALTER, DROP, CREATE, etc. and all the statements end with a semicolon (;).
The syntax is the language that any programming language like SQL understands. It is a set of rules and procedures to be followed to execute a particular code.


23. What are relationships in SQL Server database?


A. One-to-One Relationship
B. Many-to-One Relationship


One-to-One Relationship

one to many

Many-to-Many Relationship

Many to Many
24. What is SQL Injection

It is a technique through which a hacker can inject malicious SQL commands into SQL statements to modify and manipulate the data. They can steal data or delete it completely to cause significant loss to the user database.

25. What are Query types in SQL?


• DDL- Data Definition Language
• DCL- Data Control Language
• DML- Data Manipulation Language
• TCL- Transaction Control Language

26. What does ACID stand for in SQL?

                                   

These are the parameters for database testing.

27. Difference between CHAR & VARCHAR data types in SQL.

The fundamental difference between the two is that of the length of datatype.

CHAR is fixed in length, while VARCHAR has a variable length. 

28. What are Triggers?

Triggers are set of commands or actions specified in a given database that is executed when there are changes introduced by the user inputs like insert, delete, etc.

There are two types:
A. DDL trigger
B. DML trigger

29. What is a BOOLEAN data field?

BOOLEAN FIELD is used to define a column or variable in a table. It stores only TRUE or False data values in a single byte of data.


30. What is a Database snapshot?

It is a read-only view and backup of a SQL database. It is available whenever a need to query the database arises.

Some frequently asked questions related to SQL Tester interviews:

1. Where can I practice SQL coding?

Search the internet, look for free SQL tutorials, study blogs, and websites like this.

2. Which are few good sites for practicing SQL coding?

SQL Fiddle, W3resource, and others.

3.What are constraints in SQL programming language?

  • Not Null
  • Default
  • Unique
  • Check
  • Index
  • Primary Key
  • Foreign Key

4. What is a Sub-Query in SQL server?


It is also known as an inner query and is found inside other queries.

5. What is a database table?

A database table consists of rows and columns in which data is stored. It stays their till it is deleted permanently.

I hope we have provided an exhaustive list of questions that are most likely to be asked in any SQL query related interviews for testers.


More Resources : Work from home jobs in Hyderabad | Work from home jobs in Mumbai | Logical questions for interview | Codeigniter interview questions

- Advertisement -spot_img

More articles

- Advertisement -spot_img

Latest article