SQL Server DBA Interview Questions and Answers: Answer
SQL Server DBA Interview Questions and Answers: Answer
and answers
Question.1 Which TCP/IP port does SQL Server run on? How can it be changed?
Answer: SQL Server runs on port 1433. It can be changed from the Network Utility TCP/IP
properties.
Question.2 What are the difference between clustered and a non-clustered index?
Answer: A clustered index is a special type of index that reorders the way records in the
table are physically stored. Therefore table can have only one clustered index. The leaf nodes
of a clustered index contain the data pages. A non clustered index is a special type of index in
which the logical order of the index does not match the physical stored order of the rows on
disk. The leaf node of a non clustered index does not consist of the data pages. Instead, the
leaf nodes contain index rows.[sociallocker]
Question.3 What are the different index configurations a table can have?
Answer: A table can have one of the following index configurations:
No indexes
A clustered index
A nonclustered index
Accent sensitivity
Kana Sensitivity – When Japanese kana characters Hiragana and Katakana are treated
differently, it is called Kana sensitive.
Width sensitivity – A single-byte character (half-width) and the same character represented as
a double-byte character (full-width) are treated differently than it is width sensitive.
TRUNCATE removes the data by deallocating the data pages used to store the table’s data,
and only the page deallocations are recorded in the transaction log.
TRUNCATE removes all rows from a table, but the table structure, its columns, constraints,
indexes and so on, remains. The counter used by an identity for new rows is reset to the seed
for the column.
You cannot use TRUNCATE TABLE on a table referenced by a FOREIGN KEY constraint.
Because TRUNCATE TABLE is not logged, it cannot activate a trigger.
DELETE:
DELETE removes rows one at a time and records an entry in the transaction log for each
deleted row.
If you want to retain the identity counter, use DELETE instead. If you want to remove table
definition and its data, use the DROP TABLE statement.
Note: DELETE and TRUNCATE both can be rolled back when surrounded by
TRANSACTION if the current session is not closed. If TRUNCATE is written in Query
Editor surrounded by TRANSACTION and if session is closed, it can not be rolled back but
DELETE can be rolled back.
A sub-query must be put in the right hand of the comparison operator, and
Types of Sub-Query
Question.12 What are the authentication modes in SQL Server? How can it be
changed?
Answer: Windows mode and Mixed Mode – SQL and Windows. To change authentication
mode in SQL Server click Start, Programs, Microsoft SQL Server and click SQL Enterprise
Manager to run SQL Enterprise Manager from the Microsoft SQL Server program group.
Select the server then from the Tools menu select SQL Server Configuration Properties, and
choose the Security page.
Question.13 Which command using Query Analyzer will give you the version of SQL
server and operating system?
Answer: SELECT SERVERPROPERTY (‘productversion’), SERVERPROPERTY
(‘productlevel’), SERVERPROPERTY (‘edition’).
Question.14 What is SQL Server Agent?
Answer: SQL Server agent plays an important role in the day-to-day tasks of a database
administrator (DBA). It is often overlooked as one of the main tools for SQL Server
management. Its purpose is to ease the implementation of tasks for the DBA, with its full-
function scheduling engine, which allows you to schedule your own jobs and scripts.
Question.15 Can a stored procedure call itself or recursive stored procedure? How
much level SP nesting is possible?
Answer: Yes. Because Transact-SQL supports recursion, you can write stored procedures
that call themselves. Recursion can be defined as a method of problem solving wherein the
solution is arrived at by repetitively applying it to subsets of the problem. A common
application of recursive logic is to perform numeric computations that lend themselves to
repetitive evaluation by the same processing steps. Stored procedures are nested when one
stored procedure calls another or executes managed code by referencing a CLR routine, type,
or aggregate. You can nest stored procedures and managed code references up to 32 levels.
Question.16 What is Log Shipping?
Answer: Log shipping is the process of automating the backup of database and transaction
log files on a production SQL server, and then restoring them onto a standby server.
Enterprise Editions only supports log shipping. In log shipping the transactional log file from
one server is automatically updated into the backup database on the other server. If one server
fails, the other server will have the same db and can be used this as the Disaster Recovery
plan. The key feature of log shipping is that it will automatically backup transaction logs
throughout the day and automatically restore them on the standby server at defined interval.
Question.17 Name 3 ways to get an accurate count of the number of records in a table?
Answer:
SELECT * FROM table1
What is a Database?
A Database Administrator needs to know what a database is before they can administer it, right?
At its most basic, a database is a collection of tables, structured in such a way that it can be
navigated like you would any sort of table. If you remember in math class, you may have had a
number of tables that allowed you to quickly find a value if you multiplied an x and y value
together — or in this case, what it would be if you were looking for a particular row and column
value.
Why should I go to all the trouble of creating a database when I have a perfectly good Excel
Spreadsheet?
Scale. If you were to take a (singular) spreadsheet and a (singular) table and place them side by
side, there would be effectively no difference in the data you are seeing or what you could do
with it. As you go bigger and bigger with more and more tables and spreadsheets, if you have a
black belt in spreadsheet-fu you can accomplish many of the same tasks that a database could
do as well. The problem is, as you go larger and larger and larger, that it becomes much more
difficult to be human-friendly and still be efficient when it comes to processing data. So should
you replace every single spreadsheet with a database? Not necessarily, but if the data on that
spreadsheet needs to be accessed quickly by multiple users simultaneously and is growing
rapidly, it may be time to consider going to the dark side (they have cookies).
What is a query?
A query in normal terms is a question, simple enough. It is the statement that is talking to the
database in order to Create, Read, Update or Delete (CRUD) data. While many times a query is
an actual question asking for an answer, it can also be the statement to modify, insert, or remove
data in the database as well.
What is SQL?
Structured Query Language is the basic way of asking a database server to talk to you. Whether
that is in the context of asking it a question, giving it answers to questions it is asking you, or
updating answers that have already been stored in the database. The art of asking the right
question is critical to getting back the right data you need, which is incredibly valuable when
dealing with databases, as it is very easy to receive far more data than you know what to do with,
or nothing at all.
What is a Frontend?
For those that don’t want to see row upon row upon row of data in front of them until they go
cross-eyed, a frontend is essential. In essence a management program, a frontend allows
admins to be able to view and modify high level database functions without the need to use the
command line for every single thing. This can be extremely useful not only for efficiency, but also
for safety, as it can prevent accidental data modification. It can also allow users that are more
used to a GUI application most of the utility that the CLI permits.
What is a ‘join’?
Well when two tables love each other very much…not that much happens actually. However
when you need to search across multiple tables simultaneously, a join can help make that
happen. For example, if you were searching for information on a particular product and one table
has the description while the other has pricing information, you can use a join to search across
both tables simultaneously using a single query.
SQL Vs NoSQL
NoSQL (Also called Not Only SQL), is a different form of database than the standard relational
type. While it can use a lot of the same kinds of query language, it doesn’t necessarily use the
same type of table structure that standard relational databases use, and thus in some cases can
be more efficient. That efficiency depends greatly on its application however, and many times
you will see NoSQL used in Big Data crunching and analysis applications that require real-time
feedback.
I have a database that was built in MySQL, and I need the data to be moved over to Microsoft SQL
Server. How would I do this?
The easy answer would be to contact Microsoft Tech Support and bring your checkbook. A more
difficult answer would be to bring it down to a .csv file and then import it into SQL Server, but
without a specialty conversion utility you may lose some program-specific specific tricks, thus
requiring some rebuilding once the conversion is complete. This is not saying that this would
work in all cases, but it is at least an option.
Why do database servers benefit from a lot of memory, and why do 64-bit operating systems help in
this regard?
Database servers like to cache as much data as possible when they are reading it a lot. Storing
this information in active memory is a lot faster than trying to find it again from the hard disk or
other media. Therefore more memory = faster response time = better performance. The problem
is that for most operating systems the maximum amount of memory that can be used by a 32-bit
OS is 4 gigabytes. While in years past this would have been an inconceivable number, today it is
a drop in the bucket. 64-bit operating systems resolve this issue by being able to handle memory
to 192 gigabytes currently for Windows, while Linux can theoretically go much higher at present,
and these numbers will only climb higher and higher.
Why is it difficult to use standard file by file backup methods on an active database server?
This problem is twofold. First, many database servers place locks on database files that are
currently in use. Most backup programs that try to do a file-by-file backup will therefore be unable
to create a copy of this file, as they cannot get exclusive permissions to it. Second, while some
database servers have only a single file to backup a database, others have multiple files that can
be stored in different locations across possibly multiple physical hard disks. The problem can be
resolved in one of two potential ways. First, using the backup method within the database server
itself. Some programs such as Microsoft SQL Server allow you to create a scheduled backup
directly within the server application to a location of your choosing. Others require you to use a
scheduled task or another on-demand type of backup solution. The second would be to use a
backup application that can talk directly to the database server, allowing the database to be
backed up using a different technique.
When would you use an offline backup method versus an online backup?
If the above methods are unavailable when trying to create a backup solution, another potential
method is temporarily taking down the database or database server in order to create a file-by-
file backup. The problem with this method is that if the server goes down incorrectly, the backups
could be flagged as bad and thus unusable. Periodically testing your backups to make sure they
are working properly is strongly recommended, regardless of what method you use to create them.
What is Replication?
Database replication allows for real-time automated backups between multiple database servers.
This allows for the creation of either a fall-over server, or warm backup for use in case the main
server goes down.
What is XML?
Extensible Markup Language (XML) is a fast way to display data that not only conforms to a
structure that can be read by machines, but is also easily understandable by humans. Because
they can be dynamically and manually generated in many different ways, they are easy to
produce and map to; and because they retain the same structure despite the data being updated,
they can be relied upon for automatic functions such as RSS aggregation.
What is ODBC?
Open Database Connectivity is a way to make different kinds of frontends talk to different data
sources (DSNs) such as Databases. The specifics available depend on the type of application
being used, the driver being used and the backend to which it is being applied.
What is Normalization?
When most people first start working with databases, the first instinct is to create massive tables
for storing data — one place, one query — keeps things simple. However, as they grow to
unmanageable levels, it is a good idea to look into Database Normalization. This idea allows for
data to be split off into smaller more efficient tables that (hopefully) reduce the amount of
duplicate data. In this way, smaller queries can be run on individual tables instead of having
everybody always talking to one big one — thus improving performance.
What are the default ports for MySQL, SQL Server and Oracle, and can/should this be changed?
The default port for MySQL is 3306, and can be changed in Windows as noted in this article or in
*nix as noted in this article. The default port for Microsoft SQL Server is 1433, and can be
changed as noted in this article. The default port for Oracle is 1521, and can be changed as noted
in this article. Depending on your security stance, changing the port that your database server
uses can be a good way to lower your profile and reduce the amount of unauthorized access
attempts against the server.
For Microsoft SQL Server, What is Log Shipping?
A form of backup on Microsoft SQL Server, Log Shipping is similar to replication and allows for
rapid failover if the main server goes down. One thing to bear in mind, however, is that a log
shipping based failover must be activated manually; it will not switch over automatically.
What is Hadoop?
Hadoop is a Data Mining application designed to handle very, very large amounts of data across
a wide variety of environments — from one to thousands of systems. Used in situations that don’t
necessarily fit into standard database structures, its main strength is being able to take one giant
project and split it off to each of its member servers, have them each process their own job, then
have their findings recombined into one viewable result.