SQL Server DBA Interview Questions and Answers
SQL Server DBA Interview Questions and Answers
Ans: Yes! Adding CPUs can occur physically by adding new hardware, logically by online
hardware partitioning, or virtually through a virtualization layer. Starting with SQL
Server 2008, SQL Server supports hot-add CPU.
Requires the 64-bit edition of Windows Server 2008 Datacenter or the Windows
Once the CPU is added just run RECONFIGURE then the SQL server recognizes the newly
added CPU.
2. How can we check whether the port number is connecting or not on a Server?
Ans:
HTTP TCP 80
Ans:
The default SQL Server port is 1433 but only if it’s a default install. Named instances get a
random port number.
Reporting services is a web service – so it’s port 80, or 443 if it’s SSL enabled.
The analysis service is on 2382 but only if it’s a default install. Named instances
Ans: No not possible for SQL Server 2005. To rollback an SP you have to uninstall the
entire product and reinstall it.
For SQL Server training Bangalore 2008 you can uninstall an SP from Add/Remove
programs.
Some people are saying that we can do it by backup and replace the resource DB. But I am
not sure about that.
7. What is a deadlock and what is a live lock? How will you go about resolving
deadlocks?
Ans: Deadlock is a situation when two processes, each having a lock on one piece of data,
attempt to acquire a lock on the other’s piece. Each process would wait indefinitely for the
other to release the lock unless one of the user processes is terminated. SQL Server
detects deadlocks and terminates one user’s process.
A livelock is one, where a request for an exclusive lock is repeatedly denied because a
series of overlapping shared locks keeps interfering. SQL Server detects the situation after
four denials and refuses further shared locks. A livelock also occurs when read transactions
monopolize a table or page, forcing a write transaction to wait indefinitely.
Once you connect to the master database run the diagnostic quires to find the problem
Ans: I am not going to say one is better than others, but it depends on the requirements.
We have a number of products in the market. But if I have the chance to choose one of
them I will choose SQL SERVER because…..
According to the 2005 Survey of Wintercorp, The largest SQL Server DW database is the
19.5 terabytes. It is a database of a European Bank
Speed and Concurrency, SQL Server 2005 system is able to handle 5,000 transactions per
second and 100,000 queries a day and can scale up to 8 million new rows of data per day,
Finally, more technical peoples are available for SQL SERVER when we compare to any
other database.
So that we can say SQL SERVER is more than enough for any type of application.
11. What are the Hotfixes and Patches?
Ans: Hotfixes are software patches that were applied to live i.e. still running systems.
A hotfix is a single, cumulative package that includes one or more files that are used to
address a problem in a software product (i.e. a software bug).
In a Microsoft SQL SERVER context, hotfixes are small patches designed to address
specific issues, most commonly to freshly-discovered security holes.
Ex: If a select query returning duplicate rows with aggregations the result may be wrong….
12. Why Shrink file/ Shrink DB/ Auto Shrink is really bad?
Ans: In the SHRINKFILE command, SQL Server isn’t especially careful about where it puts
the pages being moved from the end of the file to open pages towards the beginning of the
file.
The data becomes fragmented, potentially up to 100% fragmentation, this is a performance
killer for your database;
The operation is slow – all pointers to/from the page/rows being moved have to be fixed up,
and the SHRINKFILE operation is single-threaded, so it can be really slow (the single-threaded
nature of SHRINKFILE is not going to change any time soon)
Recommendations:
Shrink the file by using Truncate Only: First, it removes the inactive part of the log and then
performs a shrink operation
Ans: Memory and disk storage both refer to internal storage space in a computer. The term
“memory” usually means RAM (Random Access Memory). The terms “disk space” and
“storage” usually refer to hard drive storage.
15. What port do you need to open on your server firewall to enable named pipes
connections?
Ans: Port 445. Named pipes communicate across TCP port 445.
16. What are the different log files and how to access it?
Ans: SQL Server Error Log: The Error Log, the most important log file, is used to
troubleshoot system problems. SQL Server retains backups of the previous six logs, naming
each archived log file sequentially. The current error log file is named ERRORLOG. To view
the error log, which is located in the %Program-Files%Microsoft SQL
ServerMSSQL.1MSSQLLOGERRORLOG directory, open SSMS, expand a server node,
expand Management, and click SQL Server Logs
SQL Server Agent Log: SQL Server’s job scheduling subsystem, SQL Server Agent,
maintains a set of log files with warning and error messages about the jobs it has run,
written to the %ProgramFiles%Microsoft SQL ServerMSSQL.1MSSQLLOG directory. SQL
Server will maintain up to nine SQL Server Agent error log files. The current log file is
named SQLAGENT.OUT, whereas archived files are numbered sequentially. You can view
SQL Server Agent logs by using SQL Server Management Studio (SSMS). Expand a server
node, expand Management, click SQL Server Logs, and select the checkbox for SQL
Server Agent.
Windows Event Log: An important source of information for troubleshooting SQL Server
errors, the Windows Event log contains three useful logs. The application log records
events in SQL Server and SQL Server Agent and can be used by SQL Server Integration
Services (SSIS) packages. The security log records authentication information, and the
system log records service startup and shutdown information. To view the Windows Event
log, go to Administrative Tools, Event Viewer.
SQL Server Setup Log: You might already be familiar with the SQL Server Setup log,
which is located at %ProgramFiles%Microsoft SQL Server90Setup
BootstrapLOGSummary.txt. If the summary.txt log file shows a component failure, you can
investigate the root cause by looking at the component’s log, which you’ll find in the
%Program-Files%Microsoft SQL Server90Setup BootstrapLOGFiles directory.
SQL Server Profiler Log: SQL Server Profiler, the primary application-tracing tool in SQL
Server, captures the system’s current database activity and writes it to a file for later
analysis. You can find the Profiler logs in the log .trc file in the %ProgramFiles%Microsoft
SQL ServerMSSQL.1MSSQLLOG directory.
17. Explain XP_READERRORLOG or SP_READERRORLOG?
Ans: I would store these as XML based files and not in the MSDB database. With the
configuration files, you can point the packages from prod to dev (and vice versa) in just a
few seconds. The packages and config files are just stored in a directory of your choice.
Resources permitting, create a standalone SSIS server away from the primary SQL Server
19. We have a table which is 1.2 GB in size, we need to write an SP which should
work with a particular point of time data (like a snapshot) (We should not use
snapshot Isolation as it takes other 1.2 TB size)?
Ans: You may want to add insert timestamps and update timestamps for each record.
Every time a new record is inserted, stamp it with the DayTime and also stamp it with the
date-time when updated. Also possibly use partitioning to reduce index rebuilds.
20. What is RAID levels? Which one we have to choose for SQL Server user
databases?
Ans: Check out the charts in this document. It shows how the disks are setup. It will depend
on what the customer wants to spend and the level of reliability needed. Raid 5 is common,
but see the topic ‘RAID 10 versus RAID 5 in Relational Databases’, in the document below.
It’s a good discussion. Raid 10 (pronounced Raid one-zero) is supposed to have the best in
terms of performance and reliability, but the cost is higher.
21. How many datafiles I can put in Tempdb? What is the effect of adding
multiple data files?
Ans: By far, the most effective configuration is to set tempdb on its own separate fast drive
away from the user databases. I would set the number of files based on # of cpu’s divided
by 2. So, if you have 8 cpu’s, then set 4 tempdb files. Set the tempdb large enough with
10% data growth. I would start at a general size of 10 GB for each size. I also would not
create more than 4 files for each mdf/ldf even if there were more than 8 cpu’s. you can
always add more later.
22. Let’s say a user is performing a transaction on a clustered server and failover
has occurred. What will happen to the Transaction?
Ans: If it is active/passive, there is a good chance the transaction died, but active/passive is
considered by some the better as it is not as difficult to administer. I believe that is what we
have on active. Still, active/active may be best depending on what the requirements are for
the system.
23. How you do which node is active and which is passive. What are the
criteria for deciding the active node?
Ans: Open Cluster Administrator, check the SQL Server group where you can see the
current owner. So the current owner is the active node and other nodes are passive.
24. What are the common trace flags used with SQL Server?
Ans: All sys objects are physically stored in the resource database and logically available
on every database.
Resource database can faster the service packs or upgrades
26. Really does resource faster the upgrades? Can you justify it?
Ans: Yes, in earlier versions upgrades requires dropping and recreating system objects
now an upgrade requires a copy of the resource file.
We are also capable of the rollback the process because it just needs to overwrite the
existing with the older version resource copy.
27. I have my PROD SQL server all system DB's are located on E drive and I need
my resource db on H drive how can you move it?
Ans:
mssqlsystemresource.mdf and
mssqlsystemresource.ldf
30. What you do if a column of data type int is out of scope?
Ans: 433
33. What is a system database and what is a user database?
Ans: System databases are the default databases that are installed when the SQL Server
is installed. Basically, there are 4 system databases: Master, MSDB, TempDB, and Model.
It is highly recommended that these databases are not modified or altered for the smooth
functioning of the SQL System.
A user database is a database that we create to store data and start working with the data.
34. What is the importance of a recovery model?
Ans: Primarily, the recovery model is chosen to keep in view the amount of data loss one
can afford to. If one expects to have minimal or no data loss, choosing the Full recovery
model is a good choice. Depending on the recovery model of a database, the behavior of
database log file changes. I would recommend you read more material on log backups and
log file behavior and so on to understand in depth.
35. What is Replication?
Ans: Replication is a feature in SQL Server that helps us publish database objects and data
and copy (replicate) it to one or more destinations. It is often considered as one of the High-
Availability options. One of the advantages of Replication is that it can be configured on
databases which are in simple recovery model.
36.What the different types of Replication and why are they used?
Ans: There are basically 3 types of replication: Snapshot, Transactional and Merge
Replication. The type of Replication you choose depends on the requirements and/or the
goals one is trying to achieve. For example, Snapshot Replication is useful only when the
data inside the tables does not change frequently and the amount of data is not too large,
such as a monthly summary table or a product list table, etc. Transactional Replication
would useful when maintaining a copy of a transactional table such as sales.
37. What Changes In The Front End Code Is Needed If Mirroring Is Implemented
For The High Availability?
Ans: 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;”.
38. Where Does The Copy Job Runs In The Log Shipping Primary Or Secondary?
Ans: Secondary server. This question is basically asked to find out whether you have a
hands on work on log shipping or not.