Interview Questions: SQL Server DBA
Questions
- Explain SQL Server Failover Clustering?
- How do we check index Fragmentation?
- TSQL syntax for Index rebuild and reorg. Difference between the two. How users are effected?
- How do we rebuild large indexes?
- Detect Locks in SQL Server.
- Simulate a deadlock situation. Explain how SQL Server handles and comes out of the situation.
- List out some commonly used DMVs.
- Function to retrieve file level space usage.
- List out and Explain some useful DBCC commands.
- How do we store datafiles in a network drive.
- Faster way of counting rows in a table.
- What do we do when tempdb is full.
- Whats the role of MSDTC.
- Expalin two phase commit.
- Steps before and after SQL Server upgrade. And steps to perform to enhance performance or prevent performance problems as a result of upgrade.
- Isolation levels in SQL Server.
- Restore a database from suspect mode without using Backup.
- Frequestly used stored procedures and functions.
- TLOG for tempdb is full and is not shrinking with shrink command. How do we take care of this issue?
- What all activities happen during a checkpoint?
- Events that can trigger a checkpoint.
- How to change checkpoint interval? and whats the default interval?
- Activities happening while a SQL Server instance starts.
- What is 3GB switch?
- Find memory usage of three instances respectively in a Server from Task manager.
- How can a database go into suspect mode?
- Different modes for a database in SQL Server.
- Find tables that has no indexes.
- Move indexes to a separate file group.
- Will log-shipping work for bulk logged recovery model?
- Different modes of Database mirroring?
- Role of Cluster Quorum disk.
- Two communication methods between the nodes of cluster.
Part 2
- Maximum Number of instances possible in a SQL Server?
- 50 instances on a stand-alone server for all SQL Server editions. SQL Server supports 25 instances on a failover cluster when using a shared cluster disk as the stored option for you cluster installation SQL Server supports 50 instances on a failover cluster if you choose SMB file shares as the storage option for your cluster installation.
- Frequency at which the merge agent checks for changes at publisher and subscriber in a merge replication.
- By default 60. Right click merge agent and look for pol interval inside agent profile from management studio.
- Main differences in installation steps for 2005 and 2008 failover cluster.
- Best recommended replication possible for sales person who do not have access to Office internal LAN. Keep in mind that they can connect only through internet without vpn.
- Enable web synchronization. Refer http://msdn.microsoft.com/en-us/library/ms151810.aspx and http://msdn.microsoft.com/en-us/library/ms345214.aspx
- What happens to a table if it doesn’t have a clustered index? Ans: It becomes a heap.
Answers and Clues
a. Group of independent servers that work together to increase the availability of applications and services, protecting against software and hardware failiures by failing over resources from one server to another as required.
b. Failover cluster requires one or more clustered servers (called nodes), configuration of shared cluster disks, two networks for communication (atleast one public and one private.)
sys.dm_db_index_physical_stats( 'database_id', 'object_id', 'index_id', 'partition_number', 'mode')
. Refer MSDN for more details.
Reorganize: This defragments the indexes by moving contents across pages making the data contiguous. Highly fragmented tabled should not be reorganized. Instead we should go with index rebuild. Index reorg is an online process and it can be stopped or cancelled anytime. The work done so far will not be rolled back as compared to index rebuild.
Rebuild: Existing Indexes are dropped and rebuilt from scratch. Enterprise Edition supports online index rebuild. If the index rebuild process is killed in the middle, entire work done on that index will be rolled back.
Refer http://technet.microsoft.com/en-us/library/ms188388.aspx for Syntax and Samples.
To automatically rebuild or reorg indexes, refer my post https://www.sherbaz.com/2011/12/automatically-rebuild-or-reorg-index-based-on-fragmentation/
Helpfull Links:
http://www.sqldbadiaries.com/2010/09/05/mr-dba-what-is-the-status-of-rebuild-index/
http://www.sql-server-performance.com/2011/index-maintenance-performance/
16. Isolation Levels in SQL Server
Command: “SET TRANSACTION <Isolation Level>”
Read Uncommitted
– Lowest
– Higher concurrency
– All concurrency problems: Dirty reads, lost updates,
Nonrepeatable reads(Inconsistent analysis) and phantom reads.
Read Committed
– Eliminates dirty-reads
– Other concurrency problems exists.
– Default Isolation level of SQL Server
Repeatable Read
– Eliminates all concurrency problems except Phantom reads.
– Does not release the shared lock once the record is read and keeps till the transaction
is over.
Serializable
– Highest Isolation level.
– Avoids all concurrency related problems.
– Its just like Repeatable read with one additional feature. Obtains key range locks based on the filters that have been used. It locks not only current records that stratify the filter, but new records that fall into same filter.
Snapshot Isolation Level
– Works on Row Versioning Technology.
– When a transaction is gonna modify something, SQL server will first store the consistence version of the record in tempdb so that when another transaction running on same isolation level requires same record, it can be taken from the version store(in Tempdb).
– Prevents all concurrency problems. And also it allows in multiple updates for same resource by different transactions cuncurrently.
Read commited snapshot
– New implementation of Read commited.
– Has to be applied at database level and not session or transaction level.
– Read committed Vs Read Commited snapshot : Pessimistic Vs Optimistic.
– Snapshot Vs Read commited Snapshot : Unlike snapshot, It always returns latest consistence version and no conflicts are detected.
– All concurrency problems will happen except dirty reads.
Above points were summarized from http://www.sql-server-performance.com/2007/isolation-levels-2005/3/
17. Recover a DB from suspect mode without backup.
Refer https://www.sherbaz.com/2012/03/error-transaction-log-file-got-damaged-or-corrupted/. The procedure is similar.