Monday, July 3, 2017

SQL Server DBA Interview Questions


Following are some sql server 2016 dba interview questions to help you in prep and revise interviews in fifteen minutes.
I have got many requests to publish first set of MSSQL DBA Interview questions. I observed that many interviewers are interested in finding out whether you worked on DB corruption or not. Here is the link to help you. Go ahead with ten most important Microsoft SQL Server DBA Interview Questions.
Interviewers are testing at least basic knowledge of clustering. Read following wires to be ready for this surprise: MSSQL Interview Question Clustering- Part1, Part2, Part3 and Part4
  1. How the data is stored physically in Columnstore Index?
  2. What is the difference between lock, block and deadlock?
  3. What is the meaning of lock escalation and why/how to stop this?
  4. How to truncate the log in sql server 2008?
  5. How to Start Service Using Powershell Commands?
  6. What changes in the front end code is needed if mirroring is implemented for the high availability?
  7. Where does the copy job runs in the logshipping… Primary or secondary?
  8. What are the ways to find what code is running for any spid?
  9. When you get following error? Error 3154: The backup set holds a backup of a database other than the existing database.
  10. Does DBCC CHECKDB requires DB to be in SINGLE_USER mode?
  11. How to view the error log for any specific instance?
  12. Why are you resigning from current position?

Answer 1:
The data is logically represented as a table but physically stored in column-wise data format. A clustered columnstore index is the physical storage of whole table. Some interviewers also ask what is Deltastore so the candidate should be ready with the answer. The deltastore is used by SQL engine to improve the performance of columnstore. Deltastore is actually a clustered index where some data is temporarily stored.
Answer 2:
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 3: 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 4: 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 MSSQL Server - DBCC LOGINFO 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 6: 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 7: 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 8: 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 9: 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 10: 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
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 11: 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))
EXEC xp_readerrorlog
SELECT * FROM #Errorlog
Answer 12: This is pretty important question. Even though you are able to answer technical questions but if you don't answer this question appropriately then your changes of getting hired could vanish. You should be able to explain how the learning from your current role will help in the new role. You should be able to answer how you will be valuable to the new role for which you are interviewing. If you are interviewing because you want to change your company for better prospects, i would insist you read Are you Ready for Layoff and Boss Compatibility Matrix articles which can give you right focus on changing the job. If you are changing your employer due to sexual harassment reasons then please read How to Handle Sexual Harassment at Workplace and spread the words for public awareness.

Most of the readers of this blog also read following interview questions so linking them here:
Powershell Interview Questions and Answers
SQL Azure Interview Questions and Answers Part – 1
SQL Azure Interview Questions and Answers Part – 2

Disclaimer: This is a personal blog. Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated. Any views or opinions are not intended to malign any religion, ethnic group, club, organization, company, or individual.

No comments:

Post a Comment