Sql server Interview Questions and Answers - Test & Download!

When is the UPDATE_STATISTICS command used?

- When the processing of large data is done, this command is used.

- Whenever large number of deletions, modification or copy takes place into the tables, the indexes need to be updated to take care of these changes. UPDATE_STATISTICS performs this job.

Differentiate between a HAVING CLAUSE and a WHERE CLAUSE.

HAVING CLAUSE

- HAVING CLAUSE is used only with the SELECT statement.
- It is generally used in a GROUP BY clause in a query.
- If GROUP BY is not used, HAVING works like a WHERE clause.

WHERE Clause

- It is applied to each row before they become a part of the GROUP BY function in a query.

What do you understand by a view? What does the WITH CHECK OPTION clause for a view do?

- A view is a virtual table that consists of fields from one or more real tables.
- It is usually used to join multiple tables and get the data.
- The WITH CHECK OPTION for a view prevents any modification to the data that does not confirm to the WHERE clause of the view definition.
- This allows the data belonging to the view to be updated through the view.

Explain query execution plan?

- The optimizer available in SQL Server optimizes the code to be effectively executed.
- A query execution plan shows how this optimizer would run the query.
- Query execution plan can be viewed by :
- Using the Show Execution Plan option available in Query Analyzer,
- Displaying Estimated Execution Plan on the query dropdown menu,
- Use the SET SHOWPLAN_TEXT ON command before running a query and capturing the execution plan event in a SQL Server Profiler trace.

What is the function of SQL Server Agent Windows service?

- It is a Windows service which handles the tasks scheduled within the SQL Server environment. These tasks are also called as job and are stored with in SQL server. The jobs may run through a trigger, a predefined schedule or on demand.

- This service is very useful in determining why a particular job did not run as intended.

Comment on Transactions.

- Using transactions we can group all SQL commands into a single unit.

- The transaction begins with some task and finishes only when all tasks within it are over.

- The transaction gets over successfully only when all commands in it are successfully over. Even if one command fails, the whole transaction fails.

- The BEGIN TRANSACTION, ROLLBACK TRANSACTION, and COMMIT TRANSACTION statements are used to work with transactions.

- A group of tasks starts with the begin statement.

- In case of any problem, the rollback command is executed to abort the transaction.

- If all the tasks run successfully, all commands are executed through commit statement.

Differentiate between a primary key and a unique key.

- By default, clustered index on the column are created by the primary key whereas nonclustered index are created by unique key.

- Primary key doesn't allow NULLs, but unique key allows one NULL.

What is recursion? Is it possible for a stored procedure to call itself or recursive stored procedure? How many levels of SP nesting are possible?

- Recursion is method of problem solving where the solution is arrived at by repetitively applying the logic and solution to the subsets of the problem.

- Transact-SQL supports recursion. So, yes it is possible for a stored procedure to call itself.

- Stored procedures and managed code references can be nested up to 32 levels.

What are the advantages of using Stored Procedures?

Following are the advantages of Stored Procedures:

- They help in reducing the network traffic and latency which in turn boosts application performance.
- They help in promoting code reuse.
- They provide better security to data.
- It is possible to encapsulate the logic using stored procedures. This allows to change stored procedure code without affecting clients.
- It is possible to reuse stored procedure execution plans, which are cached in SQL Server's memory. This reduces server overhead.

What do you mean by an execution plan? Why is it used? How would you view it?

- An execution plan can be called as a road map that graphically or textually shows the data retrieval methods which have been chosen by the SQL server query optimizer, for a stored procedure or ad- hoc query.

- It is used because it is a very useful tool for a developer to understand the performance characteristics of a query or stored procedure.

- There exists an option called "Show Execution Plan" in Query Analyzer. If this option is turned on, it will display query execution plan in separate window when the query is run again.
1 2 3 4 5 6

Can you explain about buffer cash and log Cache in sql server?
Buffer cash and log Cache in sql server - Buffer Cache: Buffer cache is a memory pool in which data pages are read. It performance of the buffer cache is indicated as follows........
What is a Trace frag? Where do we use it? - Sql server
What is a Trace frag? - Temporary setting of specific server characteristics is done by trace tags. DBCC TRACEON is the command to set the trace flags......
Describe how to use Linked Server - Sql server
Linked Server - MS SQL Server supports the connection to different OLE DB on an ad hoc basis. This persistent connection is referred as Linked Server.......
Post your comment
Discussion Board
interview
Thanks for uploading and it is very useful for interview thanks a lot
Mahesh 08-10-2016
perfect questions
the questions are so perfect, nice article than you guys!!
Raj 01-23-2016
SQL developer interview questions
Thanks for providing the above questions. Here are some more interview questions..

Q1. Explain Collation?
Ans. It is a set of rules that is used to determine that how character data can be compared and sorted.

Q2. What is cluster Index?
Ans. It is used for easy retrieval of data from the database by altering the way that the records are stored. Database sorts out rows by the column which is set to be clustered index.

Q3. What is the use of TRUNCATE Command?
Ans. TRUNCATE command also deletes the data but delete all the rows which is specified in the table. With full explanation https://intellipaat.com/interview-question/sql-developer-interview-questions/

Q4. What are the types of subquery?
Ans. There are two types of subquery i.e.
1. Correlated subquery
2. Non correlated subquery

Q5. Explain primary key?
Ans. It is combination of fields which uniquely specify a row and it have no NULL value.
softinx 09-26-2015
SQL Server interview questions and answers
What is Lock Escalation?
Lock escalation is the process of reducing the overhead of the system by converting many fine grain locks into fewer coarse grain locks. Lock escalation threshold is determined dynamically by SQL server. It doesn’t require any configuration hassles as SQL Server choose to keep lock on both row and column for the page query.

What is RAID and what are different types of RAID levels?
RAID stands for Redundant array of independent disks which was earlier called as Redundant array of inexpensive disks. It is a storage technology that has one logical unit consisting of multiple disk drive components. It increases the performance by replicating and dividing the data through many levels between multiple physical drives. There are 12 Raid Levels which are as follows:
- Level 0: it is a 'striped' disk array (provides data stripping) without fault tolerance.
- Level 1: It is used in system for “mirroring” and “duplexing” purpose.
- Level 2: in this error correction takes place
- Level 3: it provides byte level stripping also called as “bit-interleaved parity”
- Level 4: is used as “dedicated parity drive” and it provides block level striping
- Level 5: is “block interleaved distributed parity”
- Level 6: is “independent data disks with double parity.
- Level 0+1: is “a mirror of stripes” and used for replication and sharing of data among disks
- Level 10: is “a stripe of mirrors”. Multiple mirrors are created and then stripes over it.
- Level 7: It adds caching to Level 3 or 4.
- Level 50: implemented as striped array with fault tolerance
- RAID S: it is proprietary striped parity RAID system
Rohit Sharma 12-7-2011
SQL Server interview questions and answers
What's the difference between a primary key and a unique key?
- Primary key is a combination of columns which uniquely specify a row whereas a unique key is related to the superkey and can uniquely identify each row in the table.
- Primary can only be one in each table as it is one of the special cases of the unique key whereas a unique key can be many.
- Primary key enforces the NOT NULL constraint whereas unique key doesn’t. Due to this values in the unique key columns may or may not be NULL.

What is bit data type and what's the information that can be stored inside a bit column?
- Bit data type is the smallest type used in a language. It is used to store the boolean information of the form 1 (true) or 0 (false). The former versions of SQL server doesn’t support NULL type in this but recent version such as SQL server 7.0 onwards it supports NULL state as well.

Define candidate key, alternate key, and composite key.
- Candidate Key is a key which provides the uniqueness of the column(s). It identifies each row of a table as unique. It can become the primary key of the table as well. Every tabular relationship will have atleast one candidate key.
- Alternate Key is a type of candidate key which is formed when there are more than one candidate key and one of them is a primary key then other keys will act as an alternate keys. Unique keys also termed as alternate keys which prevent incorrect data from entering the table.
- Composite Key is a special type of candidate key as it is formed by combining two or more columns. This gives assurance of uniqueness of data when the columns are joined together.

What are ACID properties?
ACID is used in database and it includes the following properties such as atomicity, consistency, isolation and durability. These properties allow easy, reliable and secure database transaction. Example: Transfer of money from one bank account to another. It is used to manage the concurrency in the database table.

What is the difference between Locking and multi-versioning?
Locking is a means of not allowing any other transaction to take place when one is already in progress. In this the data is locked and there won’t be any modification taking place till the transaction either gets successful or it fails. The lock has to be put up before the processing of the data whereas
Multi-versioning is an alternate to locking to control the concurrency. It provides easy way to view and modify the data. It allows two users to view and read the data till the transaction is in progress.

Rohit Sharma 12-7-2011
SQL Server interview questions and answers
What's the difference between a primary key and a unique key?
- Primary key is a combination of columns which uniquely specify a row whereas a unique key is related to the superkey and can uniquely identify each row in the table.
- Primary can only be one in each table as it is one of the special cases of the unique key whereas a unique key can be many.
- Primary key enforces the NOT NULL constraint whereas unique key doesn’t. Due to this values in the unique key columns may or may not be NULL.

What is bit data type and what's the information that can be stored inside a bit column?
- Bit data type is the smallest type used in a language. It is used to store the boolean information of the form 1 (true) or 0 (false). The former versions of SQL server doesn’t support NULL type in this but recent version such as SQL server 7.0 onwards it supports NULL state as well.

Rohit Sharma 12-7-2011
SQL Server interview questions and answers
What is normalization? Explain different forms of normalization?

Normalization is a process of organizing the data to minimize the redundancy in the relational database management system (RDBMS). The use of normalization in database is to decompose the relations with anomalies to produce well structured and smaller relations. There are 6 forms of normalization which are as follows:-
- 1NF represents a relation with no repeating groups
- 2NF represents no non-prime attribute in the table
- 3NF defines that every non-prime attribute is non-transitively dependent on every candidate key
- 4NF defines that every non-trival multi-valued dependency in table is dependent on superkey.
- 5NF defines that every non-trival join dependency in table is implied by superkey in table.
- 6NF defines that a table features no non-trival join dependency.

What is de-normalization and what are some of the examples of it?
De-normalization is used to optimize the readability and performance of the database by adding redundant data. It covers the inefficiencies in the relational database software. De-normalization logical data design tend to improve the query responses by creating rules in the database which are called as constraints.
Examples include the following:
- Materialized views for implementation purpose such as:
- Storing the count of “many” objects in one-to-many relationship
- Linking attribute of one relation with other relations
- To improve the performance and scalability of web applications
Rohit Sharma 12-7-2011
SQL Server interview questions
What are the different index configurations a table can have?

No indexes
A clustered index
A clustered index and many nonclustered indexes
A nonclustered index
Many nonclustered indexes


What is BCP?

It is used to copy huge amount of data from tables and views.
It does not copy the structures same as source to destination.
Dheeraj 12-6-2011