Sunteți pe pagina 1din 10

sql server dba interview questions

1. What are the steps to improve the performance of a query? Number of joins and use of complex views/cursors have to be reduced. The use of the stored procedures and indexes have to be maximized.

The optimized use of the complex conditional checks and computer columns have to be in place. Tracking of performance analysis for the query helps us in identifying the right aspects to optimize.

2. How would you use the SP_ functions to identify the blocking problems? Blocking is the deadlock situation when two SQL connections race to obtain the control over the same set of rows in conflicting terms. This can be tracked by the status of WAIT present in the SP_LOCK procedures output. All the active LOCKS and the different rows that are being involved are shown in this output. The identification of the connections involved in the specific row contention lock can be identified with sp_who and sp_who2 procedures. This way the causal agents of the blocking is identifies. KILL command issued against the specific SQL connection causing the BLOCK can resolve the issue. But the permanent solution lies in the proper design of the application code to execute in concurrence across different connections.

3. What are the different types of backups? The SQL server offers 4 types of backups to suit the need of the administrator. Complete backup- The complete back up is just zipping the content of the entire database in terms of the different tables and procedures etc. This back up can server as an independent entity that can be restored in different systems with just the base SQL server installed. Transaction log backup: This is the mechanism of backing up the transaction logs that have been maintained in the server. This way the details of the database getting updated is obtained. This cannot be a stand-alone back up mechanism. But can save a lot of time if we already have the file system related to the DB backed up on the new deployment server. Differential backup: This is a subset of the complete backup, where only the modified datasets are backed up. This can save the time when we are just trying to maintain a backup server to main server.

File backup: This is the quickest way to take the backup of entire database. Instead of taking in the data actually stored in DB, the files are backed up and the file system thus obtained when combined with the transaction logs of the original system will render the database that we are trying to back up.

4. What are the different levels of isolation? The isolation represents the way of separating the database from the effects of network accesses, thereby maintaining the consistency. The different levels of isolation are: read committed: This level of isolation uses the shared locks and the reads to the database give the constant and consistent values. read uncommitted: No locks implemented. This is the least effective isolation level.

repeatable read: There are lock over the rows and values but the updates are maintained as a separate phantom row which is the next set of values for the specific record. Values can change within a specific transaction of a SQL function. SERIALIZABLE reads: This is the implementation of pure lock mechanism where one specific transaction is not allowed access to specific record before another one completes. 5. How can you start the SQL Server in the single user mode and the minimal configuration mode? The SQLServer.exe is the executable which can be called in the command prompt with the parameters -m and -f. These are the options that will start the SQL server in the user mode and minimal configuration mode respectively.

6. How can you know that statistics should be updated? Statistics represent the uniqueness for the indexes that are being used for selecting the records. This can make the query execution pretty efficient. The tables that we are dealing with if truncated and repopulated, there is a good chance that the indexes and statistics are out of sync and this is when we have to update the statistics. There are also other situations like when the table has been modified and lot of rows have been added recently or like when a server has been updated with different version of software. These also give us the reason to use the UPDATE_STATISTICS, DBCC SHOW_STATISTICS etc to update it accordingly.

7. What is replication in SQL Server? Replication refers to the moving or copying of the database elements from one system to another. This can be done in the SQL Server in one of the following methods:

Transactional. Snapshop. Merge replication.

8. Can we initiate a external COM object from within SQL? Yes we can use the stored procedure sp_OACreate to initiate the external COM object from the T-SQL.

9. What is a schema? How is it useful in SQL Serers? The Schema refers to the overall structure of the database with all related information like users, access privileges, interaction information between the different tables etc. The CREATE SCHEMA is the command that can be used to create the schema in the SQL Server. This when done can be used to re deploy the same database in another system for demonstrative or test purposes. This holds intact the underlying framework over which the database has been built.

10. What is a write-ahead log? The write-ahead log is the logging system that just updates the buffer cache of the database for the transactions and updates the logs and only then the actual changes are incorporated in the actual database. This is the reason why it is called write ahead. This helps in maintaining the consistency in the database. This can also be useful in getting the actual database values even in case of failures.

11. What is the use of check points in the transaction logs? The check points are restoration points that indicate the specific state of the database. When there is some failure int he database that is occurring before the next check point, the database can be reverted back to the previous check point and thus the database would still be consistent.

12. What is a column with identity? The column with a defined identity in turn means that there is an unique value that the system assigns to the specific column. This is similar to the AUTONumber property of the Access backend.

13. What are the different components that constitute the SQL Server architecture? The Logical component consists of the overall database structure definitions, users, groups, access permissions, collations etc. The Physical component is the one that contains the physically represented form of the database i.e the actual files. There are three types of files: 1. Primary data files: These contain the links to the other files. This file is the representation of the higher level of the database. (.mdf) 2. Secondary data files - These contain the files that contain the values and actual data as in database. 3. Log files: These represent the different types of the logging output of the SQL Server, including the transaction logs.

14. What are scrollable cursors? How are they created? The scrollable cursors are the ones that can get the entire set of rows as single entity, within which all the rows present can be accessed in any order without the open/close of cursor done for every row access. The scrollable cursors are created with the keyword SCROLL added to the CREATE Cursor statements. The scrollable cursors are useful for the access of information from different rows but not for the delete/insert of new rows.

15. What is RAID? How does it help storage of databases? The RAID stands for Redundant Array of Independent Disks. With its own RAID controllers, the RAID implements a fail-safe storage mechanism with its own backup mechanisms. There are different configurations of the RAID that all give us the ACID properties of storage along with other such facilities. This kind of storage will make the SQL Server database to be failsafe and stable. This can sometimes mean that the backup mechanisms and other such reliability measures can be taken off from the SQL Server level of operations.

16. How can you identify the version number of the SQL Server installed? The global variable @@version has the build and version information for the SQL Server and the service packs.

SQL Server DBA QandA


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 HighAvailability 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.

1. 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 doesnt allow you to truncate the log now otherwise whole purpose of a DB is defeated. Read article http://mssqlcorruptiontackle.blogspot.com/2010/12/mssqlserver-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 dont need log then have the recovery model simple instead of full. If you dont 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 cant answer this question. I never selected any candidate if he/she dont 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% Q.1. What are system databases into SQL server (2005/2008) Ans. TEMPDB, MSDEB, MASTER, MSDB, mssqlsystemresource, Q.2. What stored by the TEMPDB ? Ans. Row versions, cursor, temp objects. Q.3. What Stored by the MODEL?

Ans. Templates of new database objects, like tables and column. Q.4. What Stored by the MASTER? Ans. Servers configurations and logins. Q.5. What Stored by the MSDB? Ans. Scheduled jobs, Backup/Restore and DTA information. Q.6. Can we Perform Backup Restore operation on TEMPDB? Ans. NO Q.7. What is stored in the mssqlsystemresource database? Ans. Definition of sys objects, which logically shows into all database and DMVs. Q.8. Where the SQL Logs gets stored? Ans. Its stored into root folder SQL server, LOG folder. Q.9. What do you mean by Ded lock and Live lock in SQL server? Q.10. What Backup strategy you will keep for one TB (Tera Bite) database for minimal data lose. Ans. http://www.sqlservercentral.com/Forums/Topic1019063-3572.aspx#bm1020308 Q.11. What is the DAC connection? Ans. http://msdn.microsoft.com/en-us/library/ms189595.aspx Q.12. What is a Linked Server? Ans. Linked Servers is a concept in SQL Server by which we can add other SQL Server to a Group and query both the SQL Server databases using T-SQL Statements. Q.13. What are the Joins in SQL server? Ans. Inner Join, Outer (Left Outer & Right Outer) Joins and Cross join. Q.14. Describe the Left Outer Join & Right Outer Join. Ans. Left Outer join Retrieves the all records from LEFT table and matching from the RIGHT table, and null values where is no match. Right Outer Join just opposite. Q.15. How to find the Version of SQL server? Ans. Select @@version Q.16. How to find the Service pack installed? Ans. Ans. Select @@version Or select serverproperty (productlevel) Q.17. What are the Deference between Primary Key and Unique Key? Ans. An unique key cant not be referenced as foreign key. And it may allow on null. Q.18. What is mean by Clustered Index and Non clustered index, give syntax of creation? Ans. create clustered index index_name on empmst(card) Q.19. What is Scan Table/View and Seek Table/View When its Occurs? Ans. A Table/view SCAN occurs when no useful indexes exist. A TABLE SCAN reads all data, row by row, to find the match. Q.20. What is Scan Index and Seek index. When its Occurs? Ans. http://blog.sqlauthority.com/2007/03/30/sql-server-index-seek-vs-index-scantable-scan/ Q.21. What is SQL Profiler. What are the default templates with it? Ans. SQL Server Profiler is a graphical user interface to SQL Trace for monitoring an instance of the Database Engine or Analysis Services. You can capture and save data about each event to a file or table to analyze later. http://msdn.microsoft.com/en-us/library/ms190176(v=SQL.100).aspx Q.22. What are the DMVs?

Ans. Dynamic Management Views (DMV) return server state information that can be used to monitor the health of a server instance, diagnose problems, and tune performance. Q.23. What is the syntax to execute the sys.dm_db_missing_index_details? Ans. Select * from sys.dm_db_missing_index_details Q.24. How to Change the SQL server Authentication mode. Ans. http://mumbaisqldba.wordpress.com/2010/12/24/how-change-the-sql-serverauthentication/ Q.25. What is the New in SQL server 2008. Ans. File stream data type, Activity Monitor, Resource governor, data compression, compressed backup

S-ar putea să vă placă și