Top 50 SQL Server Interview Question for Testers

Here are the top 50 MS SQL Server Interview questions and answers. These questions are helpful for QA Testers, DBAs, or Software Engineers for preparing SQL Server interview.

Top 50 SQL Server Interview Question for Testers

Q#1. Which TCP/IP port does SQL Server run on?
Ans. By default SQL Server runs on port 1433.

Q#2. What are the difference between clustered and a non-clustered index?
Ans. A clustered index is an index that rearranges the table in the order of index itself. Its leaf nodes contain data pages. A table can have only one clustered index.

A non-clustered index is an index that does not rearranges the table in the order of index itself. Its leaf nodes contain index rows instead of data pages. A table can have many non-clustered index.

Q#3. List the different index configurations possible for a table?
Ans. A table can have one of the following index configurations:

  1. No indexes
  2. A clustered index
  3. A clustered index and many non-clustered indexes
  4. A non-clustered index
  5. Many non-clustered indexes

Q#4. What is recovery model? List the types of recovery model available in SQL Server.
Ans. Recovery model basically tells SQL Server what data should be kept in the transaction log file and for how long. A database can have only one recovery model.

It also tells SQL server that which backup is possible in a particular recovery model selected. There are three types of recovery model:

  1. Full
  2. Simple
  3. Bulk-Logged

Q#5. What are different backups available in SQL Server?
Ans. Different possible backups are:

  1. Full backup
  2. Differential Backup
  3. Transactional Log Backup
  4. Copy Only Backup
  5. File and File group backup

Q#6. What is FULL Backup?
Ans. Full backup is the most common type of backup in SQL Server. This is the complete backup of the database. It also contains part of transaction log so it can be recovered.

Q#7. What is OLTP?
Ans. OLTP means Online transaction processing which follows rules of data normalization to ensure data integrity. Using these rules complex information is broken down into most simple structure.

Q#8. What is RDBMS?
Ans. RDBMS or Relational Data Base Management Systems are database management systems that maintain data in the form of tables. We can create relationships among the tables. An RDBMS has the capability to recombine the data items from different files, providing powerful tools for data usage.

Q#9. What are the properties of the Relational tables?
Ans. Relational tables have six properties:

  1. Values are atomic.
  2. Column values are of the same kind.
  3. Each row is unique.
  4. The sequence of columns is insignificant.
  5. The sequence of rows is insignificant.
  6. Each column must have a unique name.

Q#10. What’s the difference between a primary key and a unique key?
Ans. The differences between primary key and unique key are:

  1. A Primary key is column whose values uniquely identify every row in a table. Primary key values can never be reused. They create a clustered index on the column and cannot be null.
  2. A Unique key is column whose values also uniquely identify every row in a table but they create a non-clustered index by default and it allows one NULL only.

Q#11. When is UPDATE_STATISTICS command used?
Ans. As the name implies UPDATE_STATISTICS command updated the statistics used by the index to make the search easier.

Q#12. What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?
Ans. The differences between HAVING CLAUSE and WHERE CLAUSE are:

  1. Both specify a search condition but Having clause is used only with the SELECT statement and typically used with GROUP BY clause.
  2. If GROUP BY clause is not used then Having behaves like WHERE clause only.

Q#13. What is Mirroring?
Ans. Mirroring is a high availability solution. It is designed to maintain a hot stand by server which is consistence with the primary server in terms of transaction. Transaction Log records are sent directly from principal server to secondary server which keeps secondary server up to date with the principal server.

Q#14. What are the advantages of the Mirroring?
Ans.Advantages of Mirroring are:

  1. It is more robust and efficient that Log shipping.
  2. It has automatic fail over mechanism.
  3. Secondary server is synced with the primary in near real time.

Q#15. What is Log Shipping?
Ans. Log shipping is nothing but the automation of backup and restore of a database from one server to other standalone standby server. This is one of the disaster recovery solutions. If one server fails by some reason we will have the same data available on the standby server.

Q#16. What are the advantages of Log shipping?
Ans. Advantages of Log shipping:

  1. Easy to set up.
  2. Secondary database can be used as a read only purpose.
  3. Multiple secondary stand by servers are possible
  4. Low maintenance.

Q#17. Can we take the full database backup in Log shipping?
Ans. Yes, we can take the full database backup. It won’t affect the log shipping.

Q#18. What is an execution plan?
Ans. An execution plan is graphical or textual way of showing how SQL server breaks down a query to get the required result. It helps user to determine why queries are taking more time to execute and based on the investigation user can update their queries for the maximum result.
In Query Analyzer is an option called “Show Execution Plan” (located on the Query drop-down menu). If this option is turned on it will display query execution plan in separate window when query is ran again.

Q#19. What is Stored Procedure?
Ans. A stored procedure is a set of SQL queries which can take input and send back output. And when the procedure is modified, all clients automatically gets the new version. Stored procedures reduce network traffic and improve performance. Stored procedures can be used to help ensure the integrity of the database.

Q#20. List the advantages of using Stored Procedures?
Ans.Advantages of using Stored procedures are:

  1. Stored procedure boosts application performance.
  2. Stored procedure execution plans can be reused as they cached in SQL Server’s memory which reduce server overhead.
  3. Stored procedures can be reuse.
  4. Stored procedures can encapsulate logic. You can change stored procedure code without affecting clients.
  5. Stored procedures provide better security to your data.

Q#21. What is identity in SQL?
Ans. An identity column in the SQL automatically generates numeric values. We can defined a start and increment value of identity column. Identity columns do not need to be indexed.

Q#22. What are the common performance issues in SQL Server?
Ans. Following are the common performance issues:

  1. Deadlocks
  2. Blockings
  3. Missing and unused indexes.
  4. I/O bottlenecks
  5. Poor Query plans
  6. Fragmentation

Q#23. List the various tools available for performance tuning?
Ans. There are various tools available for performance tuning:

  1. Dynamic Management Views
  2. SQL Server Profiler
  3. Server Side traces
  4. Windows Performance monitor.
  5. Query Plans
  6. Tuning advisor

Q#24. What is performance monitor?
Ans. Windows performance monitor is a tool to capture metrics for the entire server. We can use this tool for capturing events of SQL server also.
Some useful counters are – Disks, Memory, Processors, Network etc.

Q#25. What are 3 ways to get count of the number of records in a table?
Ans. SELECT * FROM table_Name
SELECT rows FROM sysindexes WHERE id = OBJECT_ID(tableName) AND indid< 2


Q#26. Can we rename a column in the output of SQL query?
Ans. Yes by using the following syntax we can do this.

SELECT column_name AS new_name FROM table_name;

Q#27. What is the difference between a Local and a Global temporary table?
Ans. If defined in inside a compound statement a local temporary table exists only for the duration of that statement but a global temporary table exists permanently in the database but its rows disappears when the connection is closed.

Q#28. What is SQL Profiler?
Ans. SQL Profiler provides graphical representation of events in an instance of SQL Server for the monitoring and investment purpose. We can capture and save the data for further analysis.
We can put filters as well to captures the specific data we want.

Q#29. What do you mean by authentication modes in SQL Server?
Ans. There are two authentication modes in SQL Server.

  1. Windows mode
  2. Mixed Mode – SQL and Windows.

Q#30. How can we check SQL Server version?
Ans. By running the following command:

SELECT @@Version

Q#31. Is it possible to call a stored procedure within a stored procedure?
Ans. Yes, we call a stored procedure within a stored procedure It is called recursion property of SQL server and these type of stored procedures are called nested stored procedures.

Q#32. What is SQL Server Agent?
Ans. SQL Server agent allows us to schedule the jobs and scripts. It helps is implementing the day to day DBA tasks by automatically executing them on a scheduled basis.

Q#33. What is PRIMARY KEY?
Ans. A Primary key is column whose values uniquely identify every row in a table. Primary key values can never be reused.

Q#34. What is UNIQUE KEY constraint?
Ans. A UNIQUE constraint enforces the uniqueness of the values in a set of columns, so no duplicate values are entered. The unique key constraints are used to enforce entity integrity as the primary key constraints.

Q#35. What is FOREIGN KEY?
Ans. When a one table’s primary key field is added to related tables in order to create the common field which relates the two tables, it called a foreign key in other tables.
Foreign Key constraints enforce referential integrity.

Q#36. What is CHECK Constraint?
Ans. A CHECK constraint is used to limit the values or type of data that can be stored in a column. They are used to enforce domain integrity.

Q#37. What is a Scheduled Jobs?
Ans. Scheduled job allows a user to run the scripts or SQL commands automatically on the scheduled basis. User can determine the order in which commands need to execute and the best time to run the job to avoid the load on the system.

Q#38. What is a heap?
Ans. A heap is a table that does not contain any clustered index or non-clustered index.

Q#39. What is BCP?
Ans. BCP or Bulk Copy is a tool by which we can copy large amount of data to tables and views. BCP does not copy the structures same as source to destination. BULK INSERT command helps to import a data file into a database table or view in a user-specified format.

Q#40. What is Normalization?
Ans. The process of table design to minimize the data redundancy is called normalization. We need to divide a database into two or more table and define relationships between them. Normalization usually involves dividing a database into two or more tables and defining relationships between the tables.

Q#41.List the different normalization forms?
Ans. The Different normalization forms are:

1NF (Eliminate Repeating Groups): Make a separate table for each set of related attributes, and give each table a primary key. Each field contains at most one value from its attribute domain.

2NF (Eliminate Redundant Data): If an attribute depends on only part of a multi-valued key, remove it to a separate table.

3NF (Eliminate Columns Not Dependent On Key): If attributes do not contribute to a description of the key, remove them to a separate table. All attributes must be directly dependent on the primary key.

BCNF (Boyce-Codd Normal Form): If there are non-trivial dependencies between candidate key attributes, separate them out into distinct tables.

4NF (Isolate Independent Multiple Relationships): No table may contain two or more 1:n or n:m relationships that are not directly related.

5NF (Isolate Semantically Related Multiple Relationships): There may be practical constrains on information that justify separating logically related many-to-many relationships.

ONF (Optimal Normal Form): A model limited to only simple (elemental) facts, as expressed in Object Role Model notation.

DKNF (Domain-Key Normal Form): A model free from all modification is said to be in DKNF.

Q#42. What is De-normalization?
Ans. De-normalization is the process of adding redundant data to a database to enhance the performance of it. It is a technique to move from higher to lower normal forms of database modeling in order to speed up database access.

Q#43. What is Trigger?
Ans. Trigger allows us to execute a batch of SQL code when a table event occurs (Insert, update or delete command executed against a specific table). Triggers are stored in and managed by DBMS. It can also execute stored procedure.

Q#44. What is the Subquery ?
Ans. A Subquery is sub set of select statements whose return values are used in filtering conditions of the main query. It can occur in a SELECT clause, FROM clause and WHERE clause. It nested inside a SELECT, INSERT, UPDATE, or DELETE statement or inside another subquery.

Types of Sub-query:

  1. Single-row sub-query: where the sub-query returns only one row.
  2. Multiple-row sub-query: where the sub-query returns multiple rows,. and
  3. Multiple column sub-query: where the sub-query returns multiple columns

Q#45. What is a Linked Server?
Ans. Linked Servers is a concept by which we can connect another SQL server to a Group and query both the SQL Servers database using T-SQL Statements

sp_addlinkedsrvloginisssed to add link server.

Q#46. What is Collation?
Ans. Collation refers to a set of rules that determine how data is sorted and compared. Character data is sorted using rules that define the correct character sequence, with options for specifying case sensitivity, accent marks, kana character types and character width.

Q#47. What is a View?
Ans. A view is a virtual table which contains data from one or more tables. Views restrict data access of table by selecting only required values and make complex queries easy. Rows updated or deleted in the view are updated or deleted in the table the view was created with. It should also be noted that as data in the original table changes, so does data in the view, as views are the way to look at part of the original table. The results of using a view are not permanently stored in the database

Q#48. Where SQL server user names and passwords are stored in SQL server?
Ans. They get stored in System Catalog Views sys.server_principals and sys.sql_logins.

Q#49. What are the properties of a transaction?
Ans. Generally these properties are referred as ACID properties. They are:

  • Atomicity
  • Consistency
  • Isolation
  • Durability

Ans. UNION – returns all distinct rows selected by either query .
UNION ALL – returns all rows selected by either query, including all duplicates.
MINUS – returns all distinct rows selected by the first query but not by the second.
INTERSECT – returns all distinct rows selected by both queries.

That’s all for now.
Hope in this article you will find answers to most frequently asked SQL Server interview questions.

Happy Learning..!!