preloader
Advanced SQL Interview Questions

Top 50 Advanced SQL Interview Questions and Answers for Practice

author image

Here we have brought you Advanced SQL Interview Questions to prepare for the upcoming job interview. This page is helpful to all the candidates who are looking for basic, intermediate, experienced 2,3,5,7, years Advanced SQL Interview Questions and Answers. Candidates can prepare from these 50+ Advanced SQL Interview Questions and Answers for their upcoming job interviews.

About Advanced SQL: It is a SQL language with advanced features like CTEs (Common Table Expressions), UDFs (User Defined Functions), Fulltext search extensions/ integration, performance tuning with new partitioning schemes, sparse columns, filtered indexes, etc.

Advanced SQL Interview Questions

1. Explain Failover clustering?

2. Explain lock escalation?

3. Explain Built-in/Administrator?

4. Differentiate between cross join and natural join?

5. Explain SQL Injection?

6. Tell the ways to execute Dynamic SQL?

7. Tell the use of Views?

8. Explain Auto Increment in SQL?

9. Differentiate between Union and Union All command?

10. Explain transactions in SQL?

11. Explain SQL Sandbox in SQL Server?

12. Differentiate between clustered and non-clustered indexes?

13. Describe types of locks in the database?

14. Explain a Table in a Database?

15. Explain database testing?

16. Explain Relationship?

17. Tell me the way to insert NULL values in a column while inserting the data?

18. Explain View in SQL?

19. Explain a Stored procedure?

20. Explain RDBMS?

21. Differentiate between DBMS and RDBMS?

22. Explain a field in a table?

23. How to sidestep duplicate records in a query?

24. Differentiate between an inner and outer join?

25. Explain the need for group functions in SQL?

26. Tell the way to send email from SQL database?

27. Tell about different types of SQL commands?

28. Explain the temp table?

29. Create a remote connection in a database?

30. Differentiate between Having clause and Where clause?

31. Can a table include numerous PRIMARY KEYs?

32. Explain Denormalization?

33. What is the biggest value that can be reserved in a BYTE data field?

34. Differentiate between NULL value, Zero, and Blank space?

35. Name some ACID properties?

36. Explain types of subquery?

37. Explain joining and name its types?

38. Explain locks in SQL?

39. Explain types of Privileges in SQL?

40. Mention the Syntax for STUFF function?

41. Explain Collation?

42. What is need to check in Database Testing?

43. Explain Normalization and its advantages?

44. Differentiate between DROP and TRUNCATE?

45. Differentiate between Nested Subquery and Correlated Subquery?

46. Discuss different Normalization forms?

47. Explain the Aggregate Functions available there in SQL?

48. State some properties of Relational databases?

49. Explain Nested Triggers?

50. Explain Cursor?


Learn More Interview Questions Here:


Advanced SQL Interview Questions and Answers

1. Explain Failover clustering?

It is primarily used for data availability and it has two machines. One machine gives the essential services and the second machine helps in running the service when the main system fails.

The primary system is occasionally monitored to review its work. This monitoring may be conducted by an independent system or a failover computer which is known as a cluster controller. In an occurrence of failure of the main computer, this failover system carries control.

2. Explain lock escalation?

It is used to transform page locks and row locks into table locks thus “escalating” the smaller or finer locks. This enhances system performance as every lock is just a memory structure. Also, multiple locks would lead to more consumption of memory. Therefore, escalation is used. Basically, lock escalation is the procedure of transforming a lot of low-level locks into higher-level locks.

3. Explain Built-in/Administrator?

It is essentially used at a time where some set-up joins some machine in the domain. It needs to be disabled instantly thereafter. For any disaster recovery, the Built-in/Administrator account will be automatically enabled. For normal operations, it should not be used.

4. Differentiate between cross join and natural join?

The cross join gives the Cartesian product or cross product of two tables whereas the natural join depends on all the columns that have similar names and data types in both the tables.

5. Explain SQL Injection?

It is a sort of database attack method where malevolent SQL statements are implanted into an entry field of a database so that once it is performed the database is unlocked for an attacker. This method is generally used for attacking Data-Driven Applications to reach sensitive data and accomplish administrative tasks on databases.

For Example: SELECT column_name(s) FROM table_name WHERE condition;

6. Tell the ways to execute Dynamic SQL?

These are the ways through which dynamic SQL can be performed:

Use these parameters to write a query.
Using EXEC.
Using sp_executesql.

7. Tell the use of Views?

A view directs to an analytical snapshot established on a table or another view. The usage of Views is:

  • Limiting access to data.
  • Making complicated queries simple.
  • Providing data independence.
  • Delivering different views of the same data.

8. Explain Auto Increment in SQL?

It permits the user to make a special number to get developed whenever a new record is put into the table. This keyword is generally needed when a PRIMARY KEY is used.

9. Differentiate between Union and Union All command?

The actual difference between them is, Union is distinct by default which means it connects the distinct result set of two or more select statements. Whereas, Union All command merges all the rows (including duplicates) in the result set of other select statements.

10. Explain transactions in SQL?

A transaction is a group of operations executed in a logical series. It is performed as a whole, if any statement in the transaction fails, the complete transaction is labeled as failed and not committed to the database.

11. Explain SQL Sandbox in SQL Server?

SQL Sandbox is the secure place in SQL Server Environment where untrusted scripts are performed. Three types of SQL sandbox are:

  • Safe Access Sandbox: In this, a user can execute SQL operations like, developing stored procedures, triggers, etc. but can’t have credentials to the memory and is also not able to create files.
  • External Access Sandbox: In this, a user can have access to files without having a right to manage the memory allocation.
  • Unsafe Access Sandbox: This sandbox holds untrusted codes where a user has memory access.

12. Differentiate between clustered and non-clustered indexes?

A table only has a single clustered index but numerous non-clustered indexes. Clustered indexes can be read faster than non-clustered indexes. Clustered indexes reserve data physically in the table or view whereas non-clustered indexes don’t reserve data in the table as use a separate structure for the data row.

13. Describe types of locks in the database?

  • Shared locks: These locks permit data to be read-only (Select operations) and stop the data updation when it is in the shared lock.
  • Update locks: These locks are applied to resources that are allowed to be updated. There can be a single update lock on a data at a time.
  • Exclusive locks: These locks are used to lock data from being altered (INSERT, UPDATE, or DELETE) by one transaction, therefore, ensuring that numerous updates can’t be made to a similar resource at the same time.
  • Intent locks: It is a notification mechanism that uses transaction conveys that plan to acquire a lock on data.
  • Schema locks: It is used for operations when the schema or structure of the database is needed to be updated.
  • Bulk Update locks: It is used for bulk operations when the TABLOCK hint is used.

14. Explain a Table in a Database?

It is a database object that is used to hold records in a field in the form of rows and columns that store data.

15. Explain database testing?

It involves inspecting the integrity of existing data in the front end with the data available in the database. It concerns validating the data in the database, inspecting that there are no orphan records, no junk records are available. It also updates records in the database and validates the value in the front end.

16. Explain Relationship?

Relations or connections between entities that anyhow relate with each other. Relationships are defined as the link between the tables in a database.

There are various relationships, namely:

  • One-to-One Relationship.
  • One-to-Many Relationship.
  • Many-to-One Relationship.
  • Self-Referencing Relationship.

17. Tell me the way to insert NULL values in a column while inserting the data?

NULL values can be inserted by using the following ways:

  • Implicitly by omitting column from column list.
  • Explicitly by specifying NULL keyword in the VALUES clause

18. Explain View in SQL?

Views in SQL are sore of virtual tables. A view contains rows and columns similar to a real table in the database. We can make a view by specifying fields from one or more tables available in the database. A View can either have all the rows of a table or specific rows depending on a specific condition.

The CREATE VIEW statement of SQL is used for making Views.

Basic Syntax:

CREATE VIEW view_name AS
SELECT column1, column2…..
FROM table_name
WHERE condition;

view_name: Name for the View
table_name: Name of the table
condition: Condition to select rows

19. Explain a Stored procedure?

A Stored Procedure is a group of SQL statements that have been made and stored in the database to execute a special task. The stored procedure takes input parameters and processes them and returns a single value like a number or text value or a result set (set of rows).

20. Explain RDBMS?

RDBMS stands for Relational Database Management System is a kind of DBMS having connections between the tables through indexes and different constraints such as primary key, foreign key, etc. The indexes and constraints help in rapid recovery and better management of data within the databases.

21. Differentiate between DBMS and RDBMS?

The main difference between DBMS and RDBMS is:

  • In RDBMS we have connections between the tables of the database. Whereas in DBMS there is no connection between the tables.
  • RDBMS has primary keys and data is reserved in tables. DBMS has no idea of primary keys with data held in navigational or hierarchical form.
  • RDBMS determines integrity constraints to follow ACID properties whereas DBMS doesn’t follow ACID properties.

22. Explain a field in a table?

A field is an entity for accumulating a particular kind of data within a table like numbers, dates, characters, etc.

23. How to sidestep duplicate records in a query?

By using SQL SELECT DISTINCT query, as it is used to return unique values. It removes all the duplicated values.

24. Differentiate between an inner and outer join?

An inner join returns rows when it has some similar data between two (or more) tables that are being compared. An outer join returns rows from both tables that contain the records that are not similar to one or both the tables.

25. Explain the need for group functions in SQL?

Group functions work on the collection of rows and yield one result per group. Some of the commonly used group functions are AVG, MAX, COUNT, MIN, VARIANCE, SUM etc.

26. Tell the way to send email from SQL database?

SQL Server has an element for sending mails. Stored procedures can also be utilized for sending mail on request. With SQL Server 2005, the MAPI client is not required for sending mails.

Ensure that the SQL Server Mail account is configured perfectly and Database Mail is enabled.

Follow the below-given script to send an e-mail.
USE [YourDB]
EXEC msdb.dbo.sp_send_dbmail
abc@intellipaat.com;pqr@intellipaat.com’
@body = ‘ A warm wish for your future endeavor’,
@subject = ‘This mail was sent using Database Mail’ ;

27. Tell about different types of SQL commands?

SQL commands are the group of commands which help in communicating and managing the data available in the database. Some SQL commands are-

  • DDL – Data Definition Language
  • DML – Data Manipulation Language
  • DCL – Data Control Language
  • TCL – Transactional Control Language

28. Explain the temp table?

It is a temporary storage structure to reserve the data temporarily.

29. Create a remote connection in a database?

Use SQL Server Surface Area Configuration Tool for allowing the remote relation in the database.

  • Click on Surface Area Configuration for Services and Connections.
  • Click on SQLEXPRESS/Database Engine/RemoteConnections.
  • Select the radio button: Local and Remote Connections and select ‘Using TCP/IP only’ under Local and Remote Connections.
  • Click on the OK button / Apply button

30. Differentiate between Having clause and Where clause?

Both define a search condition but the Having clause is operated only with the SELECT statement and generally used with the GROUP BY clause. If GROUP BY clause is not operated then Having acted like WHERE clause only.

31. Can a table include numerous PRIMARY KEYs?

No, a table is not authorized to include numerous primary keys but it permits to have one combined primary key consisting of two or more columns.

32. Explain Denormalization?

It refers to a method that is utilized to access data from higher to lower forms of a database. It helps the database managers to improve the implementation of the whole infrastructure as it presents redundancy into a table. It adds the repetitious data into a table by including database queries that integrate data from different tables into a single table.

33. What is the biggest value that can be reserved in a BYTE data field?

The biggest number that can be defined in a single byte is 11111111 or 255. The number of likely values is 256 (i.e. 255 (the biggest possible value) plus 1 (zero), or 28).

34. Differentiate between NULL value, Zero, and Blank space?

A null value is an area with no value which is different from zero value and blank space.

  • A null value is an area with no value.
  • Zero is a number
  • Blank space is the value we give. The ASCII value of space is CHAR(32).

35. Name some ACID properties?

These four are the properties of ACID. These properties promise that the database transactions are processed reliably.

  • Atomicity
  • Consistency
  • Isolation
  • Durability

36. Explain types of subquery?

Correlated subquery: These queries select the data from a table referenced in the external query. It is not viewed as a liberated query as it guides to another table and refers to the column in a table.

Non-Correlated subquery: This query is a liberated query where the output of the subquery is replaced in the main query.

37. Explain joining and name its types?

Join keyword is used to bring data from related two or more tables. It yields rows where there is a minimum of one match in both the tables contained in the join.

Types of joins are:

  • Right Join
  • Outer Join
  • Full Join
  • Cross Join
  • Self Join

38. Explain locks in SQL?

Locks in SQL are used for sustaining database integrity in case of coincidental execution of the exact piece of data.

39. Explain types of Privileges in SQL?

System Privilege: System privileges deal with an object of a special type and determine the right to execute one or more actions on it in which Admin authorizes a user to execute administrative tasks, ALTER ANY INDEX, ALTER ANY CACHE GROUP creates/ALTER/DELETE TABLE, CREATE/ALTER/DELETE VIEW, etc.

Object Privilege: This permits executing actions on an object or object of other users (s) viz. table, view, indexes, etc. Some of the object privileges are EXECUTE, INSERT, UPDATE, DELETE, SELECT, FLUSH, LOAD, INDEX, REFERENCES, etc.

40. Mention the Syntax for STUFF function?

STUFF (String1, Position, Length, String2)

  • String1 – String to be overwritten
  • Position – Starting location for overwriting
  • Length – Length of substitute string
  • String2- String to overwrite.

41. Explain Collation?

It is a collection of rules that inspect how the data is sorted by analogizing it. Like, Character data is reserved using correct character sequence along with case sensitivity, type, and accent

42. What is need to check in Database Testing?

  • Database Connectivity
  • Required Application Field and its size
  • Constraint Check
  • Stored Procedures
  • Data Retrieval and Processing With DML operations
  • Functional flow

43. Explain Normalization and its advantages?

Normalization is a procedure of managing data to dodge duplication and redundancy. Some of the advantages are:

  • Efficient data access
  • Better Database organization
  • Greater Flexibility for Queries
  • More Tables with smaller rows
  • Easier to implement Security
  • Quickly find the information
  • Reduction of redundant and duplicate data
  • Allows easy modification
  • Ensure Consistent data after modification
  • More Compact Database

44. Differentiate between DROP and TRUNCATE?

TRUNCATE deletes all rows from the table which can’t be recovered, DROP delete the whole table from the database and can’t be recovered.

45. Differentiate between Nested Subquery and Correlated Subquery?

Subquery within another subquery is known as Nested Subquery. If the result of a subquery is based on column values of the parent query table then the query is known as Correlated Subquery.

SELECT admin(SELEC Firstname+’ ‘+Lastname FROM Employee WHERE
empid=emp. admin)AS EmpAdminId FROM Employee

This query gets details of an employee from the Employee table.

46. Discuss different Normalization forms?

First Normal Form (1NF): It deletes all duplicate columns from the table. Makes a table for related data and recognizes unique column values

Second Normal Form (2NF): Follows 1NF and forms and places data subsets in a particular table and describes the relationship between tables using the primary key

Third Normal Form (3NF): Follows 2NF and deletes those columns which are not related through the primary key

Fourth Normal Form (4NF): Follows 3NF and does not describe multi-valued dependencies. 4NF is also called BCNF

47. Explain the Aggregate Functions available there in SQL?

SQL Aggregate Functions computes values from numerous columns in a table and returns a single value.

There are seven aggregate functions we use in SQL:

  • AVG(): Returns the average value from specified columns
  • COUNT(): Returns number of table rows
  • MAX(): Returns largest value among the records
  • MIN(): Returns smallest value among the records
  • SUM(): Returns the sum of specified column values
  • FIRST(): Returns the first value
  • LAST(): Returns Last value

48. State some properties of Relational databases?

  • Each column should have a special name
  • The series of columns and rows in relational databases are insignificant
  • All values are atomic and each row is special

49. Explain Nested Triggers?

Triggers may execute data modification logic by using INSERT, DELETE, and UPDATE statements. These triggers that include data modification logic and discover other triggers for data modification are known as Nested Triggers.

50. Explain Cursor?

A cursor is a database object which is used to influence data in a row-to-row manner.

The cursor follows phases as given below

  • Declare Cursor
  • Open Cursor
  • Retrieve row from the Cursor
  • Process the row
  • Close Cursor
  • Deallocate Cursor

Want to prepare for these languages:

Recent Articles