You are on page 1of 10

SQL Server DBA Interview Question and Answer

1. Can we hot add CPU to the SQL server?

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 hardware that supports hot-add CPU.

 Requires the 64-bit edition of Windows Server 2008 Datacenter or the Windows

 Server 2008 Enterprise Edition for Titanium-Based Systems operating system.

 Requires SQL Server Enterprise.

 SQL Server cannot be configured to use soft NUMA

 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:

 TELNET <HOSTNAME> PORTNUMBER

 TELNET PAXT3DEVSQL24 1433

 TELNET PAXT3DEVSQL24 1434


Common Ports:

 MSSQL Server: 1433

 HTTP TCP 80

 HTTPS TCP 443


3. What is the port numbers used for SQL Server services?

Ans:

 The default SQL Server port is 1433 but only if it’s a default install. Named instances get a
random port number.

 The browser service runs on port UDP 1434.

 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

 get a random port number.


4. Start SQL Server in different modes?

Ans: Single User Mode (-m) : sqlcmd –m –d master –S PAXT3DEVSQL11 –c –U sa –P


*******
DAC (-A): sqlcmd –A –d master –S PAXT3DEVSQL11 –c –U sa –P *******
Emergency: ALTER DATABASE test_db SET EMERGENCY
 5. How to recover a database that is in suspect stage?

Ans: ALTER DATABASE test_db SET EMERGENCY


After you execute this statement SQL Server will shutdown the database and restart it
without recovering it. This will allow you to view/query database objects, but the database
will be in read-only mode. Any attempt to modify data will result in an error similar to the
following:
Msg 3908, Level 16, State 1, Line 1 Could not run BEGIN TRANSACTION in database ‘test’
…..etc
ALTER DATABASE test SET SINGLE_USER
GO
DBCC CHECKDB (‘test’, REPAIR_ALLOW_DATA_LOSS) GO
If the DBCC CHECKDB statement above succeeds the database is brought back online
(but you’ll have to place it in multi-user mode before your users can connect to it). Before
you turn the database over to your users you should run other statements to ensure its
transactional consistency. If DBCC CHECKDB fails then there is no way to repair the
database – you must restore it from a backup.
 6. Can we uninstall/rollback service packs from SQL Server 2005?

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.

At TekSlate, we offer resources that help you in learning various IT courses.


We avail both written material and demo video tutorials.
To gain in-depth knowledge and be on par with   practical experience,explore SQL
Server DBA Training.

8. SQL Server is not responding. What is an action plan?

 Ans: Connect using DAC via CMD or SSMS

 Connect via CMD

 SQLCMD -A –U my admin login –P password -SMyServer –master

 Once you connect to the master database run the diagnostic quires to find the problem

 Correct the issue and restart the server


Find the errors from SQL log using
SQLCMD –A –SmyServer –q”Exec xp_readerrorlog” –o”C:logout.txt”
A long-running query blocking all processes and not allowing new connections
Write a query and put the script file on hard disk Ex: D:ScriptsBlockingQuery.sql
use master;
select p.spid, t.text
from sys processes p
CROSS APPLY sys.dm_exec_sql_text (sql_handle) t
where p.blocked = 0
and p.spid in
( select p1.blocked
from sys processes p1
where p1.blocked > 0
and p1.waittime > 50 )
From the command prompt run the script on the SQL server and get the result to a text file
SQLCMD -A – SMyServer -i” C:SQLScriptsGetBlockers.sql” -o” C:SQLScriptsblockers.txt”
Recently added some data files to temp DB and after that SQL Server is not
responding
This can occur when you specify new files in a directory to which the SQL Server service
account does not have access.
Start the SQL Server in minimal configuration mode using the startup parameter “–f”. When
we specify –f the SQL server creates new tempdb files at default file locations and ignores
the current tempdb data files configuration. Take care when using –f as it keeps the server
in single-user mode.
Once the server is started change the tempdb configuration settings and restart the server
in full mode by removing the flag -f
A database stays in a SUSPECT or RECOVERY_PENDING State
Try to resolve this using CheckDB and any other DBCC commands if you can.
Last and final option is put the DB in emergency mode and run CHECKDB with
repair_allow_data_loss
(Note: Try to avoid this unless you don’t have an option as you may lose large amounts of
data)
9. Why SQL server is better than other databases?

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

 High Security. It is offering a high level of security.

 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

 Rebuild / Reorganize the indexes once the shrink is done so the


Fragmentation level is decreased
13. Which key provides the strongest encryption?

Ans: AES (256 bit)


The longer the key, the better the encryption, so choose longer keys for more encryption.
However, there is a larger performance penalty for longer keys. DES is a relatively old and
weaker algorithm than AES.
AES: Advanced Encryption Standard
DES: Data Encryption Standard
14. What is the difference between memory and disk storage?

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: Xp_readerrorlog or sp_readerrorlog has 7 parameters.


Xp_readerrorlog <Log_FileNo>,<Log_Type>,<Keyword-1>,<Keyword-
2>,<Date1>,<Date2>,<’Asc’/’Desc’>
Log_FileNo: -1: All logs
0: Current log file
1: No1 archived log file etc
Log_Type: 1: SQL Server
2: SQL Agent
KeyWord-1: Search for the keyword
KeyWord-2: Search for a combination of Keyword 1 and Keyword 2
Date1 and Date2: Retrieves data between these two dates
‘Asc’/’Desc’: Order the data
Examples:
EXEC Xp_readerrorlog 0 – Current SQL Server log
EXEC Xp_readerrorlog 0, 1 – Current SQL Server log
EXEC Xp_readerrorlog 0, 2 – Current SQL Agent log
EXEC Xp_readerrorlog -1 – Entire log file
EXEC Xp_readerrorlog 0, 1, ’dbcc’ – Current SQL server log with dbcc in the string
EXEC Xp_readerrorlog 1, 1, ’dbcc’, ’error’ – Archived 1 SQL server log with dbcc and error
in the string
EXEC xp_readerrorlog -1, 1, ‘dbcc’, ‘error’, ‘2012-02-21’, ‘2012-02-22′,’desc’
Search entire sql server log file for string ‘dbcc’ and ‘Error’ within the given dates and
retrieves in descending order.
Note: Also, to increase the number of log files, add a new registry key “NumErrorLogs”
(REG_DWORD) under below location.
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSSQL.XMSSQLServer By default, this
key is absent. Modify the value to the number of logs that you want to maintain.
18. We have 300 SSIS packages those needs to be deployed to production, how
can we make it easier / short way to deploy all SSIS packages at once?

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: Deadlock Information: 1204, 1205, 1222


Network Database files: 1807
Log Record for Connections: 4013
Skip Startup Stored Procedures: 4022
Disable Locking Hints: 8755
Forces uniform extent allocations instead of mixed page allocations 1118 – (SQL 2005 and
2008) To reduce TempDB contention.
25. Do you know about the Resource Database?

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: No only resource db cannot be moved, Resource db location is always depends on


Master database location, if u want to move resource db you should also move master db.
28. Can we take the backup for Resource DB?
Ans: No way. The only way if you want to get a backup is use windows backup for option
resource MDF and pdf files.
29. Any idea what is the Resource dbmdf and ldf file names?

Ans:

 mssqlsystemresource.mdf and

 mssqlsystemresource.ldf
30. What you do if a column of data type int is out of scope?

Ans: I do alter column to BigInt


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

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.

You might also like