You are on page 1of 6

What is the difference between lock, block and deadlock?

2. What is the meaning of lock escalation and why/how to stop this?


3. How to truncate the log in sql server 2008?
4. How to Start Service Using Powershell Commands?
5. What changes in the front end code is needed if mirroring is implemented for
the high availability?
6. Where does the copy job runs in the logshipping… Primary or secondary?
7. What are the ways to find what code is running for any spid?
8. When you get following error? Error 3154: The backup set holds a backup of a
database other than the existing database.
9. Does DBCC CHECKDB requires DB to be in SINGLE_USER mode?
10. How to view the error log for any specific instance?

———————————————-

Answer 1:
Lock: DB engine locks the rows/page/table to access the data which is worked
upon according to the query.
Block: When one process blocks the resources of another process then blocking
happens. Blocking can be identified by using
SELECT * FROM sys.dm_exec_requests where blocked <> 0
SELECT * FROM master..sysprocesses where blocked <> 0
Deadlock: When something happens as follows: Error 1205 is reported by SQL
Server for deadlock.
Answer 2: When the DB engine would try to lock page first and then it escalates
locks to page and then table. If we

understand that whole table would be locked for the processing thenn this is
better to use TABLOCK hint and get complete table blocked. This is a nice way to
avoid the wastage of sql server DB engine processing for lock escalation.
Somewhere you may also need to use TABLOCKX when you want an exclusive
lock on the table in the query.

Answer 3: BACKUP LOG TestDB WITH TRUNCATE_ONLY is gone. SQL server


doesn’t allow you to truncate the log now otherwise whole purpose of a DB is
defeated. Read article
http://mssqlcorruptiontackle.blogspot.com/2010/12/mssql-server-dbcc-loginfo-
status-2-log.html to surprise interviewer with your answer. You have to make
sure whether you need log or not. If you don’t need log then have the recovery
model simple instead of full. If you don’t want the log to be accumulated in some
particular bulk logging then change the recovery model BULK LOGGED for that
duration and take one tlog backup just before and after this change. I shall
discuss this later in my later blog. BACKUP LOG command backs up the t-log and
frees the space in the log file.

Answer 4: How to Start Service Using Powershell Commands.

Answer 5: You need to add only FAILOVER PARTNER information in your front
end code. “Data Source=ServerA;Failover Partner=ServerB;Initial
Catalog=AdventureWorks;Integrated Security=True;”.

Answer 6: Secondary server. This question is basically asked to find out whether
you have a handson work on logshipping or not. I came through many cases
when candidates have mentioned logshipping experience in many projects and
they can’t answer this question. I never selected any candidate if he/she don’t
answer these kind of small questions.

Answer 7: Well there are many ways to do this.


1. find the spid which you want to analyze. An spid is assigned as soon as a client
connection is established with the SQL server. To find the spid you can run any of
the following command:
a) SP_WHO2 ‘ACTIVE’ — This will give you only active spids.
b) SELECT * FROM sys.dm_exec_requests

2. Get the spid from above two queries and use any of the following query to get
what is happening behind that spid.
a) dbcc inputbuffer(<spid>)
b) sql2005 and sql2008 – SELECT * FROM sys.dm_exec_sql_text(<sqlhandle of
that spid>)
c) sql2005 and sql2008 – SELECT * FROM fn_get_sql(<sqlhandle of that spid>)

Answer 8: The error comes when you are trying to restore the DB which already
exists. Use WITH REPLACE option to restore the DB with a different name.

Answer 9: Yes and No. This is tricky question. If you are using repair option with
CHECKDB then you have to have the DB in single user mode. Following is the
method to have your DB in a single user mode.

Use master
go
sp_dboption dbname, single, true

Following is the error which you get when you run the DBCC CHECKDB with
repair option w\o having the DB in single user mode.

The same is true for DBCC CHECKDB also.

Answer 10: There are many ways but I prefer following method. Take a scenario
when you want to find the error log when the DB was put in a single user mode.

CREATE TABLE #Errorlog (Logdate Datetime, Processinfo VARCHAR(20),Text


VARCHAR(2000))
INSERT INTO #Errorlog
EXEC xp_readerrorlog
SELECT * FROM #Errorlog
WHERE Text Like ‘%SINGLE%USER%’

This page contains SQL Server Database Admin Interview Questions. Since it is just the beginning days of
this section. I would be having many more in the coming days, suggest you to bookmark it, I’m sure you
will have plenty of Interview questions that are useful for your Interview preparation.

Explain about your SQL Server DBA Experience.

• This is a generic question often asked by many interviewers. Explain what are the different SQL
Server Versions you have worked on, what kind of administration of those instances has been done
by you. Your role and responsibilities carried out in your earlier projects that would be of
significance to the potential employer. This is the answer that lets the interviewer know how
suitable are you for the position to which you are being interviewed.

What are the different SQL Server Versions you have worked on?

• The answer would be depending on the versions you have worked on, I would say I have
experience working in SQL Server 7, SQL Server 2000, 2005 and 2008. If you have worked only
the some version be honest in saying that, remember, no one would be working on all versions, it
varies from individual to individual.

What are the different types of Indexes available in SQL Server?

• The simplest answer to this is “Clustered and Non-Clustered Indexes”. There are other types of
Indexes what can be mentioned such as Unique, XML, Spatial and Filtered Indexes. More on these
Indexes later.

What is the difference between Clustered and Non-Clustered Index?

• In a clustered index, the leaf level pages are the actual data pages of the table. When a clustered
index is created on a table, the data pages are arranged accordingly based on the clustered index
key. There can only be one Clustered index on a table.
• In a Non-Clustered index, the leaf level pages does not contain data pages instread it
contains pointers to the data pages. There can multiple non-clustered indexes on a single table.

What are the new features in SQL Server 2005 when compared to SQL Server 2000?

• There are quite a lot of changes and enhancements in SQL Server 2005. Few of them are listed
here :
o Database Partitioning
o Dynamic Management Views
o System Catalog Views
o Resource Database
o Database Snapshots
o SQL Server Integration Services
o Support for Analysis Services on a a Failover Cluster.
o Profiler being able to trace the MDX queries of the Analysis Server.
o Peer-toPeer Replication
o Database Mirroring

What are the High-Availability solutions in SQL Server and differentiate them briefly.

• Failover Clustering, Database Mirroring, Log Shipping and Replication are the High-Availability
features available in SQL Server. I would recommend reading this blog of mine which explains the
differences between these 4 features. Comparing the High Availability Features in SQL Server
2005

How do you troubleshoot errors in a SQL Server Agent Job?

• Inside SSMS, in Object explorer under SQL Server Agent look for Job Activity Monitor. The job
activity monitor displays the current status of all the jobs on the instance. Choose the particular job
which failed, right click and choose view history from the drop down menu. The execution history
of the job is displayed and you may choose the execution time (if the job failed multiple times
during the same day). There would information such as the time it took to execute that Job and
details about the error occurred.

What is the default Port No on which SQL Server listens?

• 1433
How many files can a Database contain in SQL Server?How many types of data files exists in SQL
Server? How many of those files can exist for a single database?

• A Database can contain a maximum of 32,767 files.

• There are Primarily 2 types of data files Primary data file and Secondary data file(s). There can be
only one Primary data file and multiple secondary data files as long as the total # of files is less than
32,767 files.

Following Q n A are added on Dec 30th 2010…

What is DCL?

• DCL stands for Data Control Language.

What are the commands used in DCL?

• GRANT, DENY and REVOKE.

What is Fill Factor?

• Fill Factor is a setting that is applicable to Indexes in SQL Server. The fill factor value determines
how much data is written to an index page when it is created / rebuilt.

What is the default fill factor value?

• By default the fill factor value is set to 0.

Where do you find the default Index fill factor and how to change it?

• The easiest way to find and change the default fill factor value is from Management Studio, Right
click the Server and choose properties. In the Server Properties, choose Database Settings. you
should see the default fill factor value in the top section. You can change to a desired value there.
• The other of viewing and changing this value is using sp_configure.

You might also like