Microsoft SQL Server has shown a notable popularity as a relational database management system (RDBMS) with its capability to store and retrieve data from various software applications. It has grabbed the attention of various companies and they are in a quick search for SQL Server professionals. I am here with a comprehensive overview of most asked SQL Server interview questions and answers for job hunters, hiring managers and recruiters.
This SQL server interview preparation guide explores SQL questions and answers for beginners, intermediate and experienced practitioners. It will help you to know what to expect and what to check in interviews. By the end, you will be all set to showcase your SQL Server skills and grab the opportunity.
The first thing we have to consider in an interview preparation is to understand the requirements of the targeted job. There are a variety of job roles available depending on different experience and expertise levels. Therefore, we have designed this article to cater to each kind of job role requirements. Let's start.
A beginner is the first step to start a career in this field. It requires knowledge of fundamentals like SQL, statements or commands, dialects, entities, etc. Here in this section, we will discuss the frequently asked SQL Server interview questions for beginners.
SQL (Structured Query Language) dialects are the different versions of this language. All these versions are very similar in terms of syntax and different in terms of functionalities. Some instances of these dialects are Microsoft SQL Server, MySQL, SQLite, PostgreSQL, Oracle, T-SQL, etc..
SQL dialects are the different versions of this language. All these versions are very similar in terms of their syntax and different in terms of functionalities. Some instances of these dialects are Microsoft SQL Server, MySQL, SQLite, PostgreSQL, Oracle, T-SQL and MongoDB.
SQL statements are the commands interpreted via SQL engines to execute different data operations. There are many commands available in this language to manipulate information according to needs. Here are some their types with instances -
Normalization is a method of organizing information to minimize redundancy and improve logical integrity. Here, databases are divided into two or more tables to determine a relationship between them. This technique works as a performance booster for databases. 1NF, 2NF, 3NF, BCNF, 4NF and 5NF are some common normalization techniques of this database management system.
Entities represent real-world objects or concepts that can be stored in a database, like a customer or product. Each entity corresponds to a table, and each row represents a single instance of the entity.
Related Article- What is PL/SQL- Everything You Need To Know
After completing more than 4 years of experience in this field, one may want to improve their career. It requires knowledge of advanced concepts like collation sensitivity, standby servers, statements, etc. Here are frequently asked SQL Server interview questions for intermediates, suitable for their career improvement.
Collation sensitivity defines the rules for data character string sorting and comparison. After selecting the collation for the server, database or any column, a certain characteristic will be applied to that information. It will arrange all the information according to the applied rule. These rules include correct character sequence, character width, case sensitivity, accent marks, etc. Here are some commonly used collation sensitivities -
A standby server is a replacement of an available server of a DBMS. For instance, an application is running on the main server and due to some issue, the server goes offline. Here, the app will stop running in the absence of a server. It requires an additional server to run properly without any disturbance.
This additional server is known as the standby server and is very important for the DBMS. This DBMS server has three types of additional servers, including hot standby, warm standby and cold standby.
Both of these are types of indexes available on SQL DBMS that have different functionalities. Here are some of their differences -
These three operations are performed with different statements (commands) as given below -
INSERT INTO table_name (column1, column2,...) VALUES (value1, value2,...); |
UPDATE TableName SET Column1 = NewValue1, Column2 = NewValue2, ... WHERE Condition; |
DELETE FROM TableName WHERE Condition; |
Creating a stored procedure and giving access to users are two different processes. Stored permission is created by the CREATE PROCEDURE statement. Given below is an instance of this process -
CREATE PROCEDURE procedure_name @parameter1 data_type, @parameter2 data_type, ... AS BEGIN -- SQL statements END; |
The GRANT statement is used for granting permissions to users. These permissions are given on different levels like schema, data store, table and many more. Given below is an instance of this statement -
GRANT permission_type ON [target] TO user_name; |
Let's come to role based interview questions. Here are some commonly asked SQL DBA interview questions and answers. These questions consist of the knowledge required to become a SQL database administrator. Explore this information to start your career in database management with SQL.
This DBMS has two types of authentication modes including mixed mode and windows authentication. Windows authentication is a default mode or integrated security of this system. It only trusts the window users and groups accounts for logging in the server.
Mixed mode is an additional security for some special instances. It is often used for legacy purposes and compatibility with older apps. It is enabled in case the database has to be connected with third parties by force. With this mode, only trusted users are enabled to interact with systems.
It is concealed with a step-by-step procedure. This process includes opening Configuration Manager> expanding network configuration > clicking right on protocol for server instance > selecting properties > navigating flags tab > selecting yes from hide instance option > saving the changes. The port number should be given to the connection string for establishing a connection.
Both these servers are different in terms of complexity and functionality. SQL Server is easy to learn as it uses T-SQL language with straightforward syntax. It only runs on two platforms including Linux and Windows.
Oracle is comparatively complicated to learn as it uses PL/SQL language with intricate syntax. Despite its complexity, it gives more advanced functionalities. This server runs on different platforms like Windows, Linux, Solaris and Unix.
PHYSICAL_ONLY is a command in DBCC CHECKDB for restricting checks to the integrity of the physical structure of the page and record headers. It detects checksum failures, torn pages and common hardware failures. This operation minimizes the runtime for DBCC CHECKDB on big databases and is suggested for frequent use.
DBCC CHECKDB has a command for checking the column values that are not valid for out of range. This command visualizes columns with date and time values that are either gigantic or smaller than the DATETIME datatype. It also restricts evaluating the physical integrity of the page and records. The command is -
| DBCC CHECKDB (DatabaseName) WITH DATA_PURITY, NO_INFOMSGS; |
Related Article - PostgreSQL Tutorial For Beginners
Some job roles like developers require knowledge in SSIS (SQL Server Integration Services). These developers get huge salary packages up to $130,496 per annum. Here are some frequently asked questions on integration services that will prepare you for the interview.
Listed below are the components of SSIS -
There are four elements including data flow, control flow, package explorer and event handler available in default package designer of BIDS.
Task defines a special action or activity to perform a part of a package. It is a fundamental building block of package workflows. Each task performs a particular activity including data extraction, data conversion and data loading.
Both of these are elements of SSIS. Control flow performs functions, gives structure and controls the flow of elements. The workflow in SSIS is called control flow. There should be at least one control flow in an SSIS package. It links modular data-flows together as a series of tasks for achieving a required result.
Data flow elements perform the ETL related tasks. This element is not necessary to have in SSIS. It has destinations and sources which extract and load information, transformations which customize and extend information, and paths which link transformations, sources and destinations. It has to be included to add a data flow to a package.
Following are the functionalities of this service in management studio -
Related Article- MongoDB vs MySQL - A Complete Comparative Guide
Most companies require some additional skills in SSRS (SQL server reporting services) alongside the SQL. This section consists of the most asked and important questions on reporting services. Go through this section to understand what types of questions may be asked and how to answer them.
SQL server reporting services is a server platform with detailed reporting features for different data sources. This platform comprises a complete set of tools. These tools manage, build and give reports and APIs for coordinating data and reporting processes in custom apps.
The fundamental components of this server based platform are -
Creating reports on this platform includes developing a data source > creating one or more datasets as per source requirements> adding required control from toolbox > formatting the controls > verifying and validating reports > deploying the report.
Many types of reports are created on this platform including snapshot, parameterized, click through, drill through, drill down, ad-hoc, cached, linked and subreports.
Calendar parameter is created with the following steps -
Related Article - What is PostgreSQL and What It Is Used For?
Let's come to the most experienced SQL interview questions. It gives a deep understanding in performance optimization strategies, complex queries and server administration tasks. Exploring these questions will elevent one's skills to the next level.
Managing or configuring replication from an SQL server is a multi step process. It involves identifying distributor and publisher > selecting type of replication from transactional, merge and snapshot > built publication to specify data > define subscription for delivering replicated information > monitor the performance of replication with replication monitor or SSMS > manage maintenance tasks like backup, restoration or index maintenance.
BULK INSERT statement is apt for importing information from a flat file into a table. In this statement, we have to give the name of the table, let's take it as annual expenses. Then give the path to a flat file like 'C:\Path\To\Your\File.csv' and adjust ROWTERMINATOR and FIELDTERMINATOR as per requirements.
BULK INSERT [annual_expenses] FROM 'C:\Path\To\Your\File.csv' WITH ( FIELDTERMINATOR = ',', ROWTERMINATOR = '\r\n', FIRSTROW = 2 ); |
SELECT * FROM ( SELECT *, ROW_NUMBER() OVER (ORDER BY employee_no) AS RowID FROM employee ) AS temp WHERE RowID % 2 != 0; |
Non-equi join is a method of combining two joins with different conditions. Here operators like <, >, <>, != and BETWEEN are used.
SELECT b.Department_ID, b.Department_name FROM Employee a JOIN Department b ON a.Department_id <> b.Department_ID; |
CREATE VIEW best_employee AS SELECT employee_name, employee_id FROM employees WHERE salary > 40000; |
Let's discuss some advanced interview questions that may be asked by interviewers. These questions revolve around some advanced topics of this DBMS. Exploring these questions will improve your knowledge and sharpen your skills. Go through this section and become capable of joining a Silicon Valley company with a high-position job role.
ALIAS is a name given to a table WHERE statement. This name works as the identity of that table. The main reason for using ALIAS is to improve the readability of column names. It is built with the AS keyword and only exists alongside the query.
SELECT column_name AS alias_name FROM table_name; |
SELECT column_name(s) FROM table_name AS alias_name; |
This is how a table is updated in SQL -
Update pets SET breed = 'Bulldog' WHERE pet_type = 'dogs' |
The components of SSIS packages are -
The query given below can find the nth highest salary from a given employee table.
SELECT DISTINCT Salary FROM ( SELECT Salary, DENSE_RANK() OVER (ORDER BY Salary DESC) AS Rank FROM Employees ) AS RankedSalaries WHERE Rank = N; -- Replace N with actual rank number |
SELECT YEAR(SaleDate) AS SaleYear, MONTH(SaleDate) AS SaleMonth, COUNT(*) AS TotalProductsSold FROM Sales GROUP BY YEAR(SaleDate), MONTH(SaleDate) ORDER BY SaleYear, SaleMonth; |
Now we will explore the most asked Scenario-Based SQL Server Interview Questions and answers. These are mostly asked to highly experienced professionals, going for senior job roles.
Now we will explore the most asked Scenario-Based SQL Server Interview Questions and answers. These are mostly asked to highly experienced professionals, going for senior job roles.
I have faced this type of issue. A query that previously executed in 200 ms has incred the processing time up to 8 to 10 seconds. To diagnose it I followed the given strategy:
Final Fix: The slow query had a missing index after the code change. So, I have added a non-clustered index on the filtered column. It reduced execution time from 8 seconds to 250 ms.
One morning, my CPU hit 100% and the application became slow. Then, I followed the given strategy to fix it:
1. Check top CPU-consuming queries:
|
2. Found a query performing multiple table scans on a large table.
3. Stats were outdated; auto-update was disabled temporarily during maintenance.
Resolution:
|
Added a missing index to reduce scans.
There was a situation where multiple users were updating the Orders and Inventory tables simultaneously. It caused deadlocks because queries accessed the tables in different order. I used the following steps to fix it:
Additional fixes:
There was a situation where the log file grew from 5 GB to 60 GB overnight and filled the drive. It happened when database was in FULL recovery mode, but backups were not running for 2 days. I fixed it with the given steps:
1. Verified recovery model:
|
2. Took a transaction log backup to truncate inactive logs.
3. Identified a long-running open transaction using DMV queries.
4. After log backup, shrunk the log file:
|
Best prevention: Scheduled regular log backups every 2 hours.
There were a situation where multiple users complained that new orders were not visible on the dashboard. The reasons were:
Solution:
|
Well, in this guide we have listed top SQL server interview questions for different level job posts. It has included all the commonly asked topics from fundamentals to advanced level. It is suitable for both candidates and recruiters. Using this content alongside study sources will prepare candidates for their next interview. Recruiters may find out the best candidates for their company with this material.
Ans. Knowing where to start is essential to learn any technology like SQL. There are a variety of options out there like SQL tutorials, books, documentation and online courses. You just have to choose wisely.
Ans. The SQL interview questions and answers mentioned in this article are best for preparing for this interview. You can also leverage some additional resources.
Ans. The following are the 5 basic SQL commands one should know:
Yes, SQL Server is mainly easy to learn if you understand basic SQL concepts and practice regularly.