Está en la página 1de 14

Frequently Asked Questions for

Replication Administrators
SQL Server 2014
Other Versions

3 out of 3 rated this helpful - Rate this topic


The following questions and answers provide guidance on a variety of tasks faced by administrators of replicated databases.

Configuring Replication
Does activity need to be stopped on a database when it is published?
No. Activity can continue on a database while a publication is being created. Be aware that producing a snapshot can be
resource-intensive, so it is best to generate snapshots during periods of lower activity on the database (by default a snapshot
is generated when you complete the New Publication Wizard).

Are tables locked during snapshot generation?


The length of time that the locks are taken depends on the type of replication used:
For merge publications, the Snapshot Agent does not take any locks.
For transactional publications, by default the Snapshot Agent takes locks only during the initial phase of snapshot
generation.
For snapshot publications the Snapshot Agent takes locks during the entire snapshot generation process.
Because locks prevent other users from updating the tables, the Snapshot Agent should be scheduled to execute during
periods of lower activity on the database, especially for snapshot publications.

When is a subscription available; when can the subscription database be used?


A subscription is available after the snapshot has been applied to the subscription database. Even though the subscription
database is accessible prior to this, the database should not be used until after the snapshot has been applied. Use
Replication Monitor to check the status of snapshot generation and application:
The snapshot is generated by the Snapshot Agent. View the status of snapshot generation on the Agents tab for a
publication in Replication Monitor. For more information, see View Information and Perform Tasks for the Agents
Associated With a Publication (Replication Monitor).
The snapshot is applied by the Distribution Agent or Merge Agent. View the status of snapshot application in
the Distribution Agent or Merge Agent page of Replication Monitor. For more information, see View Information
and Perform Tasks for the Agents Associated With a Subscription (Replication Monitor).

What happens if the Snapshot Agent has not completed when the Distribution or Merge Agent
starts?
It will not cause an error if the Distribution Agent or Merge Agent runs at the same time as the Snapshot Agent. However,
you must be aware of the following:
If the Distribution Agent or Merge Agent is configured to run continuously, the agent applies the snapshot
automatically after the Snapshot Agent completes.
If the Distribution Agent or Merge Agent is configured to run on a schedule or on-demand, and there is no
snapshot available when the agent runs, the agent will shut down with a message stating that a snapshot is not yet
available. You must run the agent again to apply the snapshot after the Snapshot Agent has completed. For more
information on running agents, see Synchronize a Push Subscription, Synchronize a Pull Subscription,
and Replication Agent Executables Concepts.

Should I script my replication configuration?


Yes. Scripting the replication configuration is a key part of any disaster recovery plan for a replication topology. For more
information on scripting, see Scripting Replication.

What recovery model is required on a replicated database?


Replication functions properly using any of the recovery models: simple, bulk-logged, or full. Merge replication tracks
change by storing information in metadata tables. Transactional replication tracks changes by marking the transaction log,
but this marking process is not affected by the recovery model.

Why does replication add a column to replicated tables; will it be removed if the table isn't
published?
To track changes, merge replication and transactional replication with queued updating subscriptions must be able to
uniquely identify every row in every published table. To accomplish this:
Merge replication adds the column rowguid to every table, unless the table already has a column of data
type uniqueidentifier with the ROWGUIDCOL property set (in which case this column is used). If the table is
dropped from the publication, the rowguid column is removed; if an existing column was used for tracking, the
column is not removed.
If a transactional publication supports queued updating subscriptions, replication adds the
column msrepl_tran_version to every table. If the table is dropped from the publication,
the msrepl_tran_version column is not removed.
A filter must not include the rowguidcol used by replication to identify rows. By default this is the column added at
the time you set up merge replication and is namedrowguid.

How do I manage constraints on published tables?


There are a number of issues to consider regarding constraints on published tables:
Transactional replication requires a primary key constraint on each published table. Merge replication does not
require a primary key, but if one is present, it must be replicated. Snapshot replication does not require a primary
key.
By default, primary key constraints, indexes, and check constraints are replicated to Subscribers.
The NOT FOR REPLICATION option is specified by default for foreign key constraints and check constraints; the
constraints are enforced for user operations but not agent operations.
For information on setting the schema options that control whether constraints are replicated, see Specify Schema Options.

How do I manage identity columns?


Replication provides automatic identity range management for replication topologies that include updates at the Subscriber.
For more information, see Replicate Identity Columns.

Can the same objects be published in different publications?


Yes, but with some restrictions. For more information, see the section "Publishing Tables in More Than One Publication" in
the topic Publish Data and Database Objects.

Can multiple publications use the same distribution database?


Yes. There are no restrictions on the number or types of publications that can use the same distribution database. All
publications from a given Publisher must use the same Distributor and distribution database.
If you have multiple publications, you can configure multiple distribution databases at the Distributor to ensure that the data
flowing through each distribution database is from a single publication. Use the Distributor Properties dialog box
or sp_adddistributiondb (Transact-SQL) to add a distribution database. For more information about accessing the dialog box,
see View and Modify Distributor and Publisher Properties.

How do I find information on the Distributor and Publisher, such as which objects in a database
are published?
This information is available through SQL Server Management Studio, and a number of replication stored procedures. For
more information, see Distributor and Publisher Information Script.

Does replication encrypt data?


No. Replication does not encrypt data that is stored in the database or transferred over the network. For more information,
see the "Encryption" section of the topic Security Overview (Replication).

How do I replicate data over the Internet?


Replicate data over the Internet using:
A Virtual Private Network (VPN). For more information, see Publish Data over the Internet Using VPN.

The Web synchronization option for merge replication. For more information, see Web Synchronization for Merge
Replication.
All types of Microsoft SQL Server replication can replicate data over a VPN, but you should consider Web synchronization if
you are using merge replication.

Does replication resume if a connection is dropped


Yes. Replication processing resumes at the point at which it left off if a connection is dropped. If you are using merge
replication over an unreliable network, consider using logical records, which ensures related changes are processed as a unit.
For more information, see Group Changes to Related Rows with Logical Records.

Does replication work over low bandwidth connections? Does it use compression?
Yes, replication does work over low bandwidth connections. For connections over TCP/IP, it uses the compression provided
by the protocol but does not provide additional compression. For Web synchronization connections over HTTPS, it uses the
compression provided by the protocol and also additional compression of the XML files used to replicate changes.

Logins and Object Ownership


Are logins and passwords replicated?
No. You could create a DTS package to transfer logins and passwords from a Publisher to one or more Subscribers.

What are schemas and how are they replicated?


Beginning with Microsoft SQL Server 2005, schema has two meanings:
The definition of an object, such as a CREATE TABLE statement. By default, replication copies the definitions of all
replicated objects to the Subscriber.
The namespace within which an object is created: <Database>.<Schema>.<Object>. Schemas are defined using
the CREATE SCHEMA statement.
Replication has the following default behavior in the New Publication Wizard with respect to schemas and object
ownership:
For articles in merge publications with a compatibility level of 90 or higher, snapshot publications, and
transactional publications: by default, the object owner at the Subscriber is the same as the owner of the
corresponding object at the Publisher. If the schemas that own objects do not exist at the Subscriber, they are
created automatically.
For articles in merge publications with a compatibility level lower than 90: by default, the owner is left blank and is
specified as dbo during the creation of the object on the Subscriber.
For articles in Oracle publications: by default, the owner is specified as dbo.
For articles in publications that use character mode snapshots (which are used for non-SQL Server Subscribers and
SQL Server Compact Subscribers): by default, the owner is left blank. The owner defaults to the owner associated
with the account used by the Distribution Agent or Merge Agent to connect to the Subscriber.
The object owner can be changed through the Article Properties - <Article> dialog box and through the following stored
procedures: sp_addarticle, sp_addmergearticle,sp_changearticle, and sp_changemergearticle. For more information,
see View and Modify Publication Properties, Define an Article, and View and Modify Article Properties.

How can grants on the subscription database be configured to match grants on the publication
database?
By default, replication does not execute GRANT statements on the subscription database. If you want the permissions on the
subscription database to match those on the publication database, use one of the following methods:
Execute GRANT statements at the subscription database directly.
Use a post-snapshot script to execute the statements. For more information, see Execute Scripts Before and After
the Snapshot Is Applied.
Use the stored procedure sp_addscriptexec to execute the statements.

What happens to permissions granted in a subscription database if a subscription is reinitialized?


By default, objects at the Subscriber are dropped and recreated when a subscription is reinitialized, which causes all granted
permissions for those objects to be dropped. There are two ways to handle this:
Reapply the grants after the reinitialization using the techniques described in the previous section.
Specify that objects should not be dropped when the subscription is reinitialized. Prior to reinitialization, either:
o Execute sp_changearticle or sp_changemergearticle. Specify a value of 'pre_creation_cmd'
(sp_changearticle) or 'pre_creation_command' (sp_changemergearticle) for the
parameter @property and a value of 'none', 'delete' or 'truncate' for the parameter @value.

In the Article Properties - <Article> dialog box in the Destination Object section, select a value
of Keep existing object unchanged, Delete data. If article has a row filter, delete only data that
matches the filter. or Truncate all data in the existing object for the option Action if name is in use.
For more information on accessing this dialog box, see View and Modify Publication Properties.

Database Maintenance
Why can't I run TRUNCATE TABLE on a published table?
TRUNCATE TABLE is a non-logged operation that does not fire triggers. It is not permitted because replication cannot track
the changes caused by the operation: transactional replication tracks changes through the transaction log; merge replication
tracks changes through triggers on published tables.

What is the effect of running a bulk insert command on a replicated database?


For transactional replication, bulk inserts are tracked and replicated like other inserts. For merge replication, you must ensure
that change tracking metadata is updated properly.

Are there any replication considerations for backup and restore?


Yes. There are a number of special considerations for databases that are involved in replication. For more information,
see Back Up and Restore Replicated Databases.

Does replication affect the size of the transaction log?


Merge replication and snapshot replication do not affect transaction log size, but transactional replication can. If a database
includes one or more transactional publications, the log is not truncated until all transactions relevant to the publications
have been delivered to the distribution database. If the transaction log is growing too large, and the Log Reader Agent is
running on a scheduled basis, consider shortening the interval between runs. Or, set it to run in continuous mode. If it is set
to run in continuous mode (the default), ensure that it is running. For more information on checking Log Reader Agent
status, see View Information and Perform Tasks for the Agents Associated With a Publication (Replication Monitor).
Additionally, if you have set the option 'sync with backup' on the publication database or distribution database, the
transaction log is not truncated until all transactions have been backed up. If the transaction log is growing too large, and
you have this option set, consider shortening the interval between transaction log backups. For more information on backing
up and restoring databases involved in transactional replication, see Strategies for Backing Up and Restoring Snapshot and
Transactional Replication.

How do I rebuild indexes or tables in replicated databases?


There are a variety of mechanisms for rebuilding indexes. They can all be used with no special considerations for replication,
with the following exception: primary keys are required on tables in transactional publications, so you cannot drop and
recreate primary keys on these tables.

How do I add or change indexes on publication and subscription databases?


Indexes can be added at the Publisher or Subscribers with no special considerations for replication (be aware that indexes
can affect performance). CREATE INDEX and ALTER INDEX are not replicated, so if you add or change an index at, for
example, the Publisher, you must make the same addition or change at the Subscriber if you want it reflected there.

How do I move or rename files for databases involved in replication?


In versions of SQL Server prior to SQL Server 2005, moving or renaming database files required detaching and reattaching
the database. Because a replicated database cannot be detached, replication had to be removed from these databases first.
Beginning with SQL Server 2005, you can move or rename files without detaching and re-attaching the database, with no
effect on replication. For more information about moving and renaming files, see ALTER DATABASE (Transact-SQL).

How do I drop a table that is being replicated?


First drop the article from the publication using sp_droparticle, sp_dropmergearticle, or the Publication Properties <Publication> dialog box, and then drop it from the database using DROP <Object>. You cannot drop articles from
snapshot or transactional publications after subscriptions have been added; you must drop the subscriptions first. For more
information, see Add Articles to and Drop Articles from Existing Publications.

How do I add or drop columns on a published table?


SQL Server supports a wide variety of schema changes on published objects, including adding and dropping columns. For
example, execute ALTER TABLE DROP COLUMN at the Publisher, and the statement is replicated to Subscribers and then
executed to drop the column. Subscribers running versions of SQL Server prior to SQL Server 2005 support adding and
dropping columns through the stored procedures sp_repladdcolumn and sp_repldropcolumn. For more information,
see Make Schema Changes on Publication Databases.

Replication Maintenance
How do I determine if the data at Subscribers is synchronized with data at the Publisher?
Use validation. Validation reports on whether a given Subscriber is synchronized with the Publisher. For more information,
see Validate Replicated Data. Validation does not provide information on which rows if any are not synchronized correctly,
but the tablediff utility does.

How do I add a table to an existing publication?


It is not necessary to stop activity on the publication or subscription databases in order to add a table (or another object).
Add a table to a publication through the Publication Properties - <Publication> dialog box or the stored
procedures sp_addarticle and sp_addmergearticle. For more information, see Add Articles to and Drop Articles from Existing
Publications.

How do I remove a table from a publication?


Remove a table from the publication using sp_droparticle, sp_dropmergearticle, or the Publication Properties <Publication> dialog box. You cannot drop articles from snapshot or transactional publications after subscriptions have
been added; you must drop the subscriptions first. For more information, see Add Articles to and Drop Articles from Existing
Publications.

What actions require subscriptions to be reinitialized?


There are a number of article and publication changes that require subscriptions to be reinitialized. For more information,
see Change Publication and Article Properties.

What actions cause snapshots to be invalidated?


There are a number of article and publication changes that invalidate snapshots and require a new snapshot to be
generated. For more information, see Change Publication and Article Properties.

How do I remove replication?


The actions required to remove replication from a database depend on whether the database served as a publication
database, subscription database, or both.

How do I determine whether there are transactions or rows to be replicated?


For transactional replication, use stored procedures or the Undistributed Commands tab in Replication Monitor. For more
information, see View Replicated Commands and Other Information in the Distribution Database (Replication Transact-SQL
Programming) and View Information and Perform Tasks for the Agents Associated With a Subscription (Replication Monitor).
For merge replication, use the stored procedure sp_showpendingchanges. For more information,
see sp_showpendingchanges (Transact-SQL).

How far behind is the Distribution Agent? Should I reinitialize?


Use the sp_replmonitorsubscriptionpendingcmds stored procedure or the Undistributed Commands tab in Replication
Monitor. The stored procedure and tab display:
The number of commands in the distribution database that have not been delivered to the selected Subscriber. A
command consists of one Transact-SQL data manipulation language (DML) statement or one data definition
language (DDL) statement.
The estimated amount of time to deliver commands to the Subscriber. If this value is greater than the amount of
time required to generate and apply a snapshot to the Subscriber, consider reinitializing the Subscriber. For more
information, see Reinitialize Subscriptions.
For more information, see sp_replmonitorsubscriptionpendingcmds (Transact-SQL) and View Information and Perform Tasks
for the Agents Associated With a Subscription (Replication Monitor).

Replication and Other Database Features


Does replication work in conjunction with log shipping and database mirroring?
Yes. For more information, see Log Shipping and Replication (SQL Server) and Database Mirroring and Replication (SQL
Server).

Does replication work in conjunction with clustering?


Yes. No special considerations are required because all data is stored on one set of disks on the cluster.

SQL Server Replication Interview Questions


Problem
When preparing for a SQL Server interview there are several topics that could be
covered. In this tip we cover some possible interview questions and answers related to SQL
Server replication.

Solution
Here is a list of commonly asked replication interview questions or questions that may come
up during your routine DBA duties. I hope you find them useful.
EASY
1) What is SQL Server replication?

Replication is subset of SQL Server that can move data and database objects in an automated way
from one database to another database. This allows users to work with the same data at different
locations and changes that are made are transferred to keep the databases synchronized.

2) What are the different types of SQL Server replication?

Snapshot replication - As the name implies snapshot replication takes a snapshot of the published
objects and applies it to a subscriber. Snapshot replication completely overwrites the data at the
subscriber each time a snapshot is applied. It is best suited for fairly static data or if it's acceptable
to have data out of sync between replication intervals. A subscriber does not always need to be
connected, so data marked for replication can be applied the next time the subscriber is
connected. An example use of snapshot replication is to update a list of items that only changes
periodically.

Transactional replication - As the name implies, it replicates each transaction for the article being
published. To set up transactional replication, a snapshot of the publisher or a backup is taken and
applied to the subscriber to synchronize the data. After that, when a transaction is written to the
transaction log, the Log Reader Agent reads it from the transaction log and writes it to the
distribution database and then to the subscriber. Only committed transactions are replicated to
ensure data consistency. Transactional replication is widely applied where high latency is not
allowed, such as an OLTP system for a bank or a stock trading firm, because you always need realtime updates of cash or stocks.

Merge replication - This is the most complex types of replication which allows changes to happen
at both the publisher and subscriber. As the name implies, changes are merged to keep data
consistency and a uniform set of data. Just like transactional replication, an initial synchronization is
done by applying snapshot. When a transaction occurs at the Publisher or Subscriber, the change is
written to change tracking tables. The Merge Agent checks these tracking tables and sends the
transaction to the distribution database where it gets propagated. The merge agent has the

capability of resolving conflicts that occur during data synchronization. An example of using merge
replication can be a store with many branches where products may be centrally stored in inventory.
As the overall inventory is reduced it is propagated to the other stores to keep the databases
synchronized.

3) What is the difference between Push and Pull Subscription?

Push - As the name implies, a push subscription pushes data from publisher to the subscriber.
Changes can be pushed to subscribers on demand, continuously, or on a scheduled basis.

Pull - As the name implies, a pull subscription requests changes from the Publisher. This allows the
subscriber to pull data as needed. This is useful for disconnected machines such as notebook
computers that are not always connected and when they connect they can pull the data.

4) What are different replication agents and what's their purpose?

Snapshot Agent- The Snapshot Agent is used with all types of replication. It prepares the schema
and the initial bulk copy files of published tables and other objects, stores the snapshot files, and
records information about synchronization in the distribution database. The Snapshot Agent runs at
the Distributor.

Log Reader Agent - The Log Reader Agent is used with transactional replication. It moves
transactions marked for replication from the transaction log on the Publisher to the distribution
database. Each database
published using transactional replication has its own Log Reader Agent that runs on the Distributor
and connects to the Publisher (the Distributor can be on the same computer as the Publisher)

Distribution Agent - The Distribution Agent is used with snapshot replication and transactional
replication. It applies the initial snapshot to the Subscriber and moves transactions held in the
distribution database to Subscribers. The Distribution Agent runs at either the Distributor for push
subscriptions or at the Subscriber for pull subscriptions.

Merge Agent - The Merge Agent is used with merge replication. It applies the initial snapshot to
the Subscriber and moves and reconciles incremental data changes that occur. Each merge
subscription has its own Merge Agent that connects to both the Publisher and the Subscriber and
updates both. The Merge Agent runs at either the Distributor for push subscriptions or the
Subscriber for pull subscriptions.

Queue Reader Agent - The Queue Reader Agent is used with transactional replication with the
queued updating option. The agent runs at the Distributor and moves changes made at the
Subscriber back to the
Publisher. Unlike the Distribution Agent and the Merge Agent, only one instance of the Queue
Reader Agent exists to service all Publishers and publications for a given distribution database.

5) Does a specific recovery model need to be used for a replicated database?

Replication is not dependent on any particular recovery model. A database can participate in
replication whether it is in simple, bulk-logged, or full. However how data is tracked for
replication depends on the type of replication used.

Medium
1) What type of locking occurs during the Snapshot generation?

Locking depends on the type of replication used:

o
o
o

In snapshot replication, the snapshot agent locks the object during the entire snapshot
generation process.
In transactional replication, locks are acquired initially for a very brief time and then
released. Normal operations on a database can continue after that.
In merge replication, no locks are acquired during the snapshot generation process.

2) What options are there to delete rows on the publisher and not on the subscriber?

One option is to replicate stored procedure execution instead of the actual DELETE command. You
can create two different versions of the stored procedures one on the publisher that does the delete
and the other on the subscriber that does not do the delete.
Another option is to not replicate DELETE commands.

3) Is it possible to run multiple publications and different type of publications from the same
distribution database?

Yes this can be done and there are no restrictions on the number or types of publications that can
use the same distribution database. One thing to note though is that all publications from a
Publisher must use the same Distributor and distribution database.

4) Data is not being delivered to Subscribers, what can be the possible reasons?

There are a number of possible causes for data not being delivered to Subscribers:
o The table is filtered, and there are no changes to deliver to a given Subscriber.
o One or more agents are not running or are failing with an error.
o Data is deleted by a trigger, or a trigger includes a ROLLBACK statement.
o A transactional subscription was initialized without a snapshot, and changes have occurred
on the Publisher since the publication was created.
o Replication of stored procedure execution for a transactional publication produces different
results at the Subscriber.
o The INSERT stored procedure used by a transactional article includes a condition that is not
met.
o Data is deleted by a user, a replication script, or another application.

5) Explain what stored procedure sp_replcounters is used for?

Sp_replcounters is a system stored procedure that returns information about the transaction rate,
latency, and first and last log sequence number (LSN) for each publication on a server. This is run
on the publishing server. Running this stored procedure on a server that is acting as the distributor
or subscribing to publications from another server will not return any data

Hard
1) How will you monitor replication latency in transactional replication?

Tracer tokens were introduced with SQL Server 2005 transactional replication as a way to monitor
the latency of delivering transactions from the publisher to the distributor and from the distributor
to the subscriber(s). For details, please refer tip to this tip: Monitor SQL Server replication latency
using tracer tokens

2) If I create a publication with one table as an article, and then change the schema of the
published table (for example, by adding a column to the table), will the new schema ever be
applied at the Subscribers?

Yes. Schema changes to tables must be made by using Transact-SQL or SQL Server Management
Objects (SMO). When schema changes are made in SQL Server Management Studio, Management
Studio attempts to drop and re-create the table and since you cannot drop a published objects, the
schema change will fail.

3) Is it possible to replicate data from SQL Server to Oracle?

Yes this can be done using heterogeneous replication. In SQL Server 2000, publishing data to other
databases such as DB2 or Oracle was supported; however, publishing data from other databases
was not supported without custom programming. In SQL Server 2005 and later versions, Oracle
databases can be directly replicated to SQL Server in much the same way as standard SQL Server
replication. For more information, please read tip:Introduction to SQL Server Heterogeneous
Replication

4) How will you monitor replication activity and performance? What privilege do you need to
use replication monitor?

The easiest way to monitor replication activity and performance is to use replication monitor, but
you can also use the below tools to monitor replication performance:
o T-SQL commands. For more details refer msdn article - http://msdn.microsoft.com/enus/library/ms147874.aspx
o Microsoft SQL Server Management studio. For more details refer msdn article http://msdn.microsoft.com/en-us/library/ms152763.aspx
To monitor replication, a user must be a member of the sysadmin fixed server role at the Distributor
or a member of the replmonitor fixed database role in the distribution database. A system
administrator can add any user to the replmonitor role, which allows that user to view replication
activity in Replication Monitor; however, the user cannot administer replication.

5) Can you tell me some of the common replication DMV's and their use?

sys.dm_repl_articles - Contains information about each article being published. It returns data
from the database being published and returns a row for each object being published in each article.
sys.dm_repl_schemas - Contains information about each table and column being published. It
returns data from the database being published and returns one row for each column in each object
being published
sys.dm_repl_traninfo - Contains information about each transaction in a transactional replication

Sample SQL DBA Interview Questions


1. What is the difference between lock, block and deadlock?
DB engine locks the rows/page/table to access the data which is worked upon according to the query.
When one process blocks the resources of another process then blocking happens. Blocking can be identified by using
System Views:sys.dm_exec_requests or master.sys.sysprocesses or SP_WHO / SP_WHO2 Stored Procedures.
Deadlock occurs whenever there is mutual Blocking between two or more process. We can use SQL Profiler to audit and
extract Deadlock Graphs.
2. What is lock escalation?
The Query Optimizer initially locks the required Rows for DML operations / Retrieval operations. This also get relevant
Pages and Completely table to be 'INTENT' Locked. If more than 50% of rows are specifically locked then this automatically
gets the complete PAGE or TABLE to be locked. Lock Escalation mechanism can be controlled by using Locking Hints.
3. How to truncate the log in SQL Server 2012?
TRUNCATE_ONLY option for Backup Log is not available with SQL Server 2012 version. SQL server does not allow us to
truncate the log. Alternatives includes choosing / changing the database to correct recovery model.

4. What is the purpose of SQL Profiler in SQL server?


SQL Profiler is a tool to monitor performance of various stored procedures. It is used to debug the queries and procedures.
Based on performance, it identifies the slow executing queries. Capture any problems by capturing the events on
production environment so that they can be solved.
5. What is COPYONLY Data Backup? How this is useful?
There are 21 types of Backups in SQL Server. A non-base FULL BACKUP is called COPYONLY Data Backup. This is used to
service 'on demand' Backup requests from end users. Using this type of Backups, we can service the 'on demand' backup
requests from end users without disturbing the Backup sequence of Jobs / Maintenance Plans or other differential Backups.
This gives us easy restore paths as well in case of DR process.
6. What are Truncate Options available in SQL Server?
Use TRUNCATE_ONLY option for SQL Server 2005 systems while performing Backup. This option is not available in SQL
Sever 2008 R2. Instead, we use ON_TRUNCATE option available.
7. What are advantages of Peer-Peer Replication?
Peer-Peer Replication decreases / nullifies the dependency on Distributor. In this Replication topology each node is
Publisher, Distributor and Subscriber. This increases availability of the database system and Failure of any node does not
impact the health of Replication process. This topology also offers automatic conflict detection and correction. Hence,
recommended in Real time.
8. What Options we use to secure Replication Data?
Ensure that SQL Browser is running and TCP/IP is enabled. Enforce TDE (Transparent Data Encryption) so that every data
bit is encrypted.
9.What are the uses of STANDBY mode in Log Shipping?
If the Restore Jobs is scheduled / delayed for longer intervals this option can be used. As uses needs to be disconnected
every time Restore Job runs(to ensure timely shipping of Transaction Logs) its recommended not to use this option for
regular, less interval Log Shipping configurations. Using this option gives us advantage of Load Balancing for READONLY
connections and Reporting purposes at the cost of timely disconnections to help success of Restore Jobs.
10. When does Error 3154 occur?
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 database name.
11. What are recommended options to be used while using DB Mirroring?
Database Mirroring is to be configured with TCP Protocol and ensure that data over each endpoint is encrypted. Better to
make use of TDE for more security.
12. Where can you find the error log information?
We can make use of SQL Profiler , SQL Server Log or use xp_readerrorlog extended Stored Procedure to retrieve the error
log information.
13. What is the status of services on passive node for fail-over cluster in SQL server?
SQL services will be in manual and stopped. Cluster service will be in automatic and started mode on both the nodes.
14. Can you move the resources after pausing the node?
Yes resources can be moved after pausing the node. But we can't move them back till the node is paused.
15. What happens if we start the Full Text Service on Passive Node.
This can be started on both the nodes as this doesn't have any dependency on SQL service or any resource which is
possessed by active node.
16. What is Data Compression?
In SQL SERVER 2008 R2, Data Compression comes in two types viz., Row Compression where It minimizes the metadata
(column information, length, offsets, etc.) associated with each record. Numeric data types and fixed length strings are
stored in variable-length storage format, just like Varchar. Page compression uses the Row compression technique
internally and also applies prefix level compression. For every column in a page, duplicate prefixes are identified. These
prefixes are saved in compression information headers (CI) which reside after page headers. A reference number is
assigned to these prefixes and that reference number is replaced wherever those prefixes are being used.
17.What are the basic functions for master, msdb, model, tempdb and resource system databases?

The master database holds information for all databases located on the SQL Server instance. As SQL Server cannot
start without a functioning master database, we must administer this database with care and monitor Start-up
Parameters in Configuration Manager.

The msdb database stores information regarding database backups, SQL Agent information, DTS packages, SQL Server
jobs, and some replication information such as for log shipping.

The tempdb holds temporary objects such as global and local temporary tables and stored procedures.
The model is essentially a template database used in the creation of any new user database created in the instance.
The resource Database is a read-only database that contains all the system objects that are included with SQL Server.
SQL Server system objects, such as sys.objects, are physically persisted in the Resource database, but they logically
appear in the sys schema of every database. The Resource database does not contain user data or user metadata.
18. What is Service Broker?
Service Broker is a message-queuing technology in SQL Server that allows developers to integrate SQL Server fully into
distributed applications. Service Broker is feature which provides facility to SQL Server to send an asynchronous,
transactional message. it allows a database to send a message to another database without waiting for the response, so
the application will continue to function if the remote database is temporarily unavailable.
19. Where SQL server user names and passwords are stored in SQL server?
They get stored in System Catalog Views sys.server_principals and sys.sql_logins.
20. What is Policy Based Management (PBM)?
Policy Based Management in SQL SERVER 2012 Administration allows you to define and enforce policies for configuring
and managing SQL Server across the enterprise. Policy-Based Management is configured in SQL Server Management
Studio (SSMS). Navigate to the Object Explorer and expand the Management node and the Policy Management node;
you will see the Policies, Conditions, and Facets nodes.
21. What is Replication with Database Mirroring?
Database mirroring can be used with replication to provide availability for the publication database. Database mirroring
involves two copies of a single database that typically reside on different computers. At any given time, only one copy of
the database is currently available to clients which are known as the principal database. Updates made by clients to the
principal database are applied on the other copy of the database, known as the mirror database. Mirroring involves
applying the transaction log from every insertion, update, or deletion made on the principal database onto the mirror
database.
22. What are Sparse Columns in SQL Server?
A sparse column is another tool used to reduce the amount of physical storage used in a database. They are the
ordinary columns that have an optimized storage for null values. Sparse columns reduce the space requirements for null
values at the cost of more overhead to retrieve non null values.

SQL DBA Interview Questions (FAQs)

1.

23. How to force a T-SQL query to execute on single CPU?


24. Which of the engine feature SSIS can take advantage of in SQL Server 2008?
25. What is the default size of the VARCHAR data types?
26. Which of the following is new feature of SQL Server 2008 Reporting Services?
27. Which system view gives performance bottleneck?
28. Which data type allows to store more than 2GB. Any limitations of these data types?
29. Which version of the SQL Server supports ISO data type?
30. How to perform Manual Fail-over in Database Mirroring?
31. How to secure Database Mirroring? Is UDP protocol supported for this?
32. What are different ways to REBUILD SQL Server database log files?
33. What are precautionary measures we need to follow for Patching activities?
34. How to perform DRAIN in Cluster environment? Any precautions to follow?
35. What are Contained Databases? How to ensure Security in Contained Databases in SQL
Server 2012?
36. What does AAG means? What are limitations of AAG in DENALI?
37. What does practical issues that may arise if we shrink SQL Server database Log Files?

What purpose does the model database server?


The model database, as its name implies, serves as the model (or template) for all databases created on the
same instance. If the model database is modified, all subsequent databases created on that instance will
pick up those changes, but earlier created databases will not. Note that TEMPDB is also created from model
every time SQL Server starts up.
How do you trace the traffic hitting a SQL Server?
SQL profiler is the SQL Server utility you can use to trace the traffic on the SQL Server instance. Traces can
be filtered to narrow down the transactions that are captured and reducing the overhead incurred for the
trace. The trace files can be searched, saved off, and even replayed to facilitate troubleshooting.
What types of replication are supported in SQL Server?
SQL Server has three types of replication: Snapshot, Merge, and Transaction. Snapshot replication creates a
snapshot of the data (point-in-time picture of the data) to deliver to the subscribers. This is a good type to
use when the data changes infrequently, there is a small amount of data to replicate, or large changes occur
over a small period of time.
Merge replication uses a snapshot to seed the replication. Changes on both sides of the publication are
tracked so the subscriber can synchronize with the publisher when connected. A typical use for this type of
replication is in a client and server scenario. A server would act as a central repository and multiple clients
would independently update their copies of the data until connected. At which time, they would all send up
their modifications to the central store.
Transaction replication also begins with a snapshot only this time changes are tracked as transactions (as
the name implies). Changes are replicated from publisher to subscriber the same as they occurred on the
publisher, in the same order as they occurred, and in near real time. This type of replication is useful when
the subscriber needs to know every change that occurred to the data (not point-in-time), when the change
volume is high, and when the subscriber needs near real-time access to the changes.
Why would you use SQL Agent?
SQL Agent is the job scheduling mechanism in SQL Server. Jobs can be scheduled to run at a set time or
when a specific event occurs. Jobs can also be executed on demand. SQL Agent is most often used to
schedule administrative jobs such as backups.
What happens on checkpoint?
Checkpoints, whether scheduled or manually executed, cause the transaction log to be truncated up to the
beginning of the oldest open transaction (the active portion of the log). That is, the dirty pages from the
buffer cache are written to disk. Storing committed transactions in the cache provides a performance gain
for SQL Server. However, you do not want the transaction log to get too big because it might consume too
many resources and, should your database fail, take too long to process to recover the database.
One important thing to note here is that SQL Server can only truncate up to the oldest open transaction.
Therefore, if you are not seeing the expected relief from a checkpoint, it could very well be that someone
forgot to commit or rollback their transaction. It is very important to finalize all transactions as soon as
possible.
What is DBCC?
DBCC statements are Database Console Commands and come in four flavors: Maintenance, Informational,
Validation, and Miscellaneous. Maintenance commands are those commands that allow the DBA to perform
maintenance activities on the database such as shrinking a file. Informational commands provide feedback

regarding the database such as providing information about the procedure cache. Validation commands
include commands that validate the database such as the ever-popular CHECKDB. Finally, miscellaneous
commands are those that obviously don't fit in the other three categories. This includes statements like
DBCC HELP, which provides the syntax for a given DBCC command.
How can you control the amount of free space in your index pages?
You can set the fill factor on your indexes. This tells SQL Server how much free space to leave in the index
pages when re-indexing. The performance benefit here is fewer page splits (where SQL Server has to copy
rows from one index page to another to make room for an inserted row) because there is room for growth
built in to the index.
Why would you call Update Statistics?
Update Statistics is used to force a recalculation of query optimization statistics for a table or indexed view.
Query optimization statistics are automatically recomputed, but in some cases, a query may benefit from
updating those statistics more frequently. Beware though that re-computing the query statistics causes
queries to be recompiled. This may or may not negate all performance gains you might have achieved by
calling update statistics. In fact, it could have a negative impact on performance depending on the
characteristics of the system.
What is a correlated sub-query?
A correlated sub-query is a nested query that is linked to the outer query. For instance, say I wanted to find
all the employees who have not entered their time for the week. I could query the Employee table to get
their first and last name, but I need to look at the TimeEntry table to see if they've entered their time or
not. I can't do a straight join here because I'm looking for the absence of time data, so I'll do a correlated
sub-query similar to this:
SELECT FirstName, LastName
FROM EMPLOYEE e
WHERE NOT EXISTS (SELECT 1 FROM TimeEntry te
WHERE te.EmpID = e.EmpID
AND te.WeekID = 35)
Notice that the inner query relates to the outer query on the employee ID, thus making it a correlated subquery. The inner query will be evaluated once per outer query row.
What authentication modes does SQL Server support?
SQL Server supports Windows Authentication and mixed-mode. Mixed-mode allows you to use both
Windows Authentication and SQL Server Authentication to log into your SQL Server. Its important to note
that if you use Windows Authentication, you will not be able to log in as sa.
Conclusion
In this article, I list the top 10 DBA interview question (as I see it anyway). I would, however, encourage
you to also ask the DBA the SQL Server Developer questions from my previous article. As I said in that
article though, every workplace and project has different needs. I hope you found at least a few that you
can use in yours.

También podría gustarte