Introduction to SQL Server Interview Questions
SQL Server is one of the heavily used RDBMS i.e. Relational Database management system, developed by Microsoft. Apart from providing a relational database, it includes other components as well as business intelligence, reporting, and analysis tool. Database creation, backup, security, and replication like feature makes SQL server one of the top database management tool. There are multiple editions of Microsoft SQL server, which are being marketed by Microsoft, aimed at multiple audiences and based on workloads ranging from single-machine applications to large internet-facing applications, having multiple users involved at the same time. Its mainstream editions include Enterprise, Standard, Web, Business intelligence, Workgroup, and Express. Enterprise edition includes a core database engine and add-on services, with multiple tools for creating and managing a SQL server cluster. The Standard edition includes a database engine, along with standalone services. A difference with the enterprise edition is that it supports less few of nodes in a cluster. All editions have their own set of features depending upon the business case scenario.
Now, if you are looking for a job that is related to SQL Server then you need to prepare for the 2021 SQL Server Interview Questions. It is true that every interview is different as per the different job profiles but still to clear the interview you need to have a good and clear knowledge of SQL Server. Here, we have prepared the important SQL Server Interview Questions and Answers which will help you get success in your interview.
In this 2021 SQL Server Interview Questions article, we shall present 10 most important and frequently used SQL Server interview questions. These questions will help students build their concepts around SQL Server and help them ace the interview.
Part 1 – SQL Server Interview Questions (Basic)
This first part covers basic SQL Server Interview Questions and Answers
Q1. What are the multiple ways to secure a SQL server?
There are multiple approaches with which a developer can ensure the safety and security of a SQL server. Some of them might be common usage while others can be more technically oriented.
- Administrator account on SQL server computer can be renamed.
- Isolate the SQL server from the web server, by setting up SSL and firewalls.
- Always control access to the data by applying roles for server, database, and application.
- NTFS permissions can be utilized to secure physical database files.
- Enable auditing with encryption, disabling the guest account.
- NT authentications should be preferred.
- Utilize a strong System administrator password, restricting physical access to SQL server.
Q2. What is a Trigger and how many types of Triggers are there?
Every time an event with a table occurs like, insert, update or delete, a batch of SQL code can be executed with an entity called Trigger. They are managed by DBMS. Triggers can also be utilized to execute a stored procedure. Triggers available in SQL server are listed below:
1. DML trigger: They are called a Data manipulation trigger. As the name suggests, they are being triggered every time, a DML command i.e. insert, update or delete occur on the table or the view.
2. DDL trigger: Any changes occur in the definition of any database object, it can be captured by the Data definition language trigger. Production and development-based environments can be controlled and managed by these triggers.
3. Logon trigger: These triggers are handy in the case; a login event of SQL server happens. It is fired before a user session is being set up in a SQL server.
Let us move to the next SQL Server Interview Questions
Q3. What is User Defined function in SQL server, how they can be created and executed?
a user might need to implement their own logic, which can be captured inside a function known as a User-defined function. A user is not anyway limited to pre-defined functions and a simplified version of a complex already defined code can be written. It is one of the biggest advantages of a User-defined function. The creation of a user-defined function can be done in the following ways:
Create Function test(@num int)
return select * from employee where empid=@num
This function can be executed as follows:
select * from a test(12)
Q4. Explain the usage of View in SQL server?
This is the basic SQL Server Interview Questions asked in an interview. Views are the most beneficial entity for an SQL server developer. There is a whole lot of complexity involved in the database schema. At the same time, customizing the data for a particular set of users can be a tedious task, which is equally complex as database schema design. These types of complexity can be abstract away with a View. They provide a mechanism to control access to specific rows and columns. Thus, the performance of a database can be improved significantly by aggregating the data,
Q5. What is the replication and why it is required on the SQL server?
It is a set of technologies for copy and distributes data and database objects from one database to another. Synchronize the data can also be achieved with replication to maintain consistency. Replication can be used to distribute data to various locations and to remote or mobile users over a certain medium of the internet. Multiple servers having data can be synchronized with the replication process using a replica set. Thus, reading capacity can be enhanced and users can be provided with a choice to selecting among different servers to perform read-write operations.
Hence keeping in mind, the above benefits, one can cite their usage on SQL server.
Part 2 – SQL Server Interview Questions (Advanced)
Let us now have a look at the advanced SQL Server Interview Questions and Answers
Q6. What is the command to create a database in an SQL server?
There is a command called ‘CREATEDATABASE’, it can be utilized to create any database on the SQL server. Its syntax is:
CREATE DATABASE database_name
Example- “Test” database can be created to CREATE DATABASE Test
Let us move to the next interview questions.
Q7. What are the merits and demerits of having an index in SQL server?
There are various merits and demerits of index usage in SQL server. Some of them can cite as:
- Indexes can help speed up a SELECT query.
- One can also search against large string values, the given index is set to full-text index.
- Indexes help to make a row unique or without any duplicate.
Some disadvantages can be:
- Indexes take additional space; thus, a disk size is being occupied.
- An index can slow down the basic operation like insert, delete, update but if where the condition has an index field, then update operation can be faster. Insert, delete, or update becomes slower since each operation index must be updated.
Let us move to the next interview questions
Q8. What is Collation in SQL server?
There is a certain set of rules which would decide how data needs to be sorted and compared in a database. These rules can be referred to as Collation. Example – Character data is sorted using rules that define the right character sequence, with an option for specifying case sensitivity, character width, etc. Collation is predefined in the SQL server, which would decide how data in the SQL server are stored and retrieved. There are various collations that exist in SQL server, but 2 are main:
Where CI is case insensitive, and CS is case sensitive.
So, by default collation is case insensitive, thus all database in it is also case-insensitive,
Q9. What is a cursor and what are its different types?
This is the frequently asked SQL Server Interview Questions in an interview. A cursor is a database object, which can utilize to retrieve the data, one row at a time from the resultset. When data needs to be updated row-by-row, cursors can be very handy. The cursor life cycle consists of mainly 5 steps.
- Declaring cursor – declared by defining SQL statement.
- Opening cursor – Opened for storing data, retrieved from the resultset.
- Fetching cursor – Once a cursor is opened, rows can be fetched one by one or in a block to perform data manipulation.
- Closing cursor – Once data manipulation is done, the cursor needs to be closed explicitly.
- Deallocation cursor – to delete cursor definition, cursors should be deallocated, released all system resources associated with a cursor.
Types of a cursor are:
- Static – These types of cursor are responsible for making a temporary copy of data and store in tempdb. Any modification done on base table is not highlighted in data return by fetches made by a cursor.
- Dynamic – As the opposite of static, they highlight all changes in a base table.
- Forward-only – cursor can only fetch sequentially from first to last.
- Keyset-driven – Keyset is the set of keys that uniquely identifies a row is built-in tempdb.
Q10. What is the difference between a UNION and a JOIN in SQL server?
A UNION select rows whereas a JOIN selects columns from two or more tables. Both can be used to combine data from multiple tables. In a nutshell, JOIN combines data into new columns, whereas UNION combines data into new rows.
This has been a guide to the list Of SQL Server Interview Questions and Answers. Here we have listed the most useful 10 interview sets of questions so that the jobseeker can crack the interview with ease. You may also look at the following articles to learn more –