SQL Server Optimization

  Home  MS SQL Server  SQL Server Optimization


“MS SQL Server Optimization job interview preparation guide for freshers and experienced candidates. Number of SQL Server Optimization frequently asked questions(FAQs) asked in many MS SQL Server Optimization interviews”



7 SQL Server Optimization Questions And Answers

2⟩ What is a deadlock and what is a live lock? How will you go about resolving deadlocks?

A deadlock can occur when two or more processes that strive to acquire resources are not able to acquire them due to some of the following reasons:

Two processes may be interdependent upon each other,

If there are more than 2 processes, then if a graph is plotted, then there could be a cycle,

A server maintains a graph. The processes acquiring the resources would intimate the server about their requirement. If the server detects an occurance of a deadlock, the user process is be terminated.

In a livelock, a request for an exclusive lock is denied repeatedly due to a series of overlapping shared locks that keep interfering.

An SQL Server detects this situation after four denials and then refuses further shared locks.

When a write transaction is forced to wait indefinitely due to read transactions that monopolize a table or a page then a live lock occurs.

 200 views

3⟩ What are the steps you will take, if you are tasked with securing an SQL Server?

Perform the following SQL checks after installing the Server:

Check if Administrators group belongs to sysadmin role

Check if CmdExec role is restricted to sysadmin only

Check if SQL Server is running on a Domain Controller

Check if sa account password is exposed

Check SQL installation folders access permissions

Check if Guest account has database access

Check if the Everyone group has access to SQL registry keys

Check if SQL service accounts are members of the local Administrators group

Check if SQL accounts have blank or simple passwords

Check for missing SQL hotfixes

Check the SQL Server authentication mode type

Check the number of sysadmin role members

Then, you should require Windows Authentication Mode for connections to SQL Server, whenever possible.

You should isolate your server and back it up regularly.

You should assign a strong sa password.

You should limit privilege level of SQL Server Services.

Configure your firewall to filter out packets addressed to TCP port 1433 and UDP port 1434. ports associated with named instances should also be blocked at the firewall.

You should Use a secure file system.

Old setup files should be Deleted or secured.

You should log failed connection attempts to SQL Server and review the log regularly.Enable auditing of failed connections with Enterprise Manager in SQL Server.

 183 views

4⟩ What is Shared lock?

Shared Lock allows simultaneous access of record by multiple Select statements.

Shared Lock blocks record from updating and will remain in queue waiting while record is accessed for reading.

If update process is going on then read command will have to wait until updating process finishes.

 172 views

7⟩ What are the lock types?

Main lock types:

Shared: Applied to read only operations where the data is not modified. E.g.: Select statements.

Update: Applied to resources which can be updated. It resolves dead locks in case of multiple sessions are reading, locking or updating resources later.

Exclusive: Used for operations involving data modification. E.g.: Insert, Update, and Delete. This ensures that multiple updates are not made to the same data at the same time.

Intent: Establishes a lock hierarchy. E.g.: Intent shared Intent exclusive and Shared with intentexclusive.

Schema: Used when schema dependent operations are being executed. E.g.: Schema modification and Schema stability.

Bulk update: Used while bulk copying of data and Tablock is specified.

 192 views