Sie sind auf Seite 1von 30



1) What is SQL Server?
Microsoft SQL Server 2005 is a database platform for large-scale online
transaction processing (OLTP), data warehousing, and e-commerce
applications; it is also a business intelligence platform for data integration,
analysis, and reporting solutions.
2) What is the Versions Available in SQL Server?
SQL Server was developed by Microsoft in 1987 and the versions are 6.0, 6.5,
7.0, 8.0(2000), 9.0(2005), 10(2008).
3) What is the Difference between SQL Server 2000 and
SQL Server-2000
SQL Server-2005
T-SQL as well as CLR
Enterprise manager
Query Analyzer
Query editor
No Reporting Tools
No Exception handling in DTS
Exception handling in SSIS
Can create up to 16 Instances
Can create up to 50 instances
No exception handling in DTS.
Exception handling in SSIS.
sa blank password.
Enforce password policy.
No database mirroring
Database mirroring.
Object oriented programming
Common language runtime
4) What are the Editions available for SQL Server 2005?
There are 6 six editions available in SQL Server 2005
a) Enterprise Edition
b) Standard Edition
c) Developer edition
d) Workgroup edition
e) Mobile edition
f) Express edition
5) What are the Tools are available in
1 Enterprise manager & Query
2 Network Client Utilities
3 SQL Profiler
4 Service manager

SQL Server 2000 and 2005?

Management Studio
Configuration manager
Surface area configuration
Database Tuning Advisor
Command Prompt Utilities

6) What are Services available in SQL Server?

There are three services available in SQL Server 2005.
a) SQL server service:- It is responsible for running Databases, System
Stored Procedures, System Indexes, User Login information and Passwords
b) SQL server agent service:- It is responsible for running Jobs, Alerts,
Notifying the operators
c) Distributed Transaction Coordinator:- It is responsible for moving data
among instances (One DB to another DB)
7) How many ways to run services?
Services are run by 5 ways they are
1) At task pane > Right click on server and click start / stop
2) Management Studio > Right click on Server and click start / stop / restart
3) Surface Area Configuration
4) Command Prompt > Net start/stop mssqlserver
5) SQL Server configuration manager > Right click on server and click start /
stop / restart.
8) What is Windows Authentication?
When Windows authentication is used to connect SQL Server, Microsoft
Windows is completely responsible for authenticating the client by identifying
its windows user account.
9) What is SQL Server Authentication?
When SQL Server authentication is used, SQL Server authenticates the client
by comparing user name and password with user names and passwords
maintained within SQL Server.
What is the difference between Windows Authentication and
SQL Server authentication?
1) Windows authentication is highly secure than SQL Server authentication
why because we need not provide any login details. So the chance of
tracing login details from code by the unauthorized persons will be less.
Windows authentication uses the default windows login credentials.
2) Windows authentication will uses the credentials of the currently logged
user to login in to the SQL Server database. Your application need not to
supply the user name and password.
3) For SQL Server authentication we have to supply the SQL database user
name and password. That will be used to get the privileges and right of
the user.
What is AWE? How configure Dynamic Memory Allocation?
Generally SQL Server reserves only a small portion of memory. Sometimes
reserved memory is not sufficient to SQL server and required additional
memory. AWE is used to support very large amounts of physical
memory. When AWE is enabled the operating system dynamically
allocates memory to SQL Server based on the Min server memory

and max server memory settings. (1) Win. Server 2003 SE supports
utpo 4GB (2) EE upto 32GB. (3) DC upto 64GB)
To Configure AWE:- Right click on instance > Properties > Memory >
Enable AWE > Set Min and Max memory etc.
Note:- AWE is not needed and cannot be configured on 64-bit operating
12) What is Linked Server? How to connect Linked server? How to test
linked Server?
One server connected with another server to execute queries against OLE DB
data sources on remote servers.
OLEDB Provider:- An OLE DB provider is a DLL that manages and interacts
with a specific data sources such as SQL Server 7.0, Access, Excel, ODBC,
Oracle, DB2, Local file system, Exchange Server etc. SQL Native Client
(PROGID: SQLNCLI) is the official OLE DB provider for SQL Server.
To connect linked server using OLE DB provider:sp_addlinkedserver
Tests the connection to a linked server:sp_testlinkedserver <servername>
13) What is purpose of Registered Servers?
Registering a server to store the server connection information for future
14) What do you mean by Collation?
Collation is basically the sort order. There are three types of sort orders
(1) Dictionary case sensitive , (2) Dictionary case insensitive, (3) Binary
What are the Protocols used in Networking? What is the
Default Port number of TCP/IP?
The protocols used in networking are TCP/IP, NAMED PIPPES, VIA, SHARED
MEMORY. The default port no of TCP/IP is 1433.
What is the Syntax used for find the SQL Server version?
1) Select @@version
2) Click on Server > Summary Reports > Server Dashboard > configuration
details > See product version.
17) What is blocking? How to identify and resolve the blockings?
Blocking happens when one user holds an exclusive lock on an object and a
second user requires an exclusive lock on the same object. This forces the
second user to wait, block on the first.
Determine Blocking sessions:- Activity Monitor, sp_who2, sp_lock,
sys.sysprocess, sys.dm_exec_requests, sys.dm_os_waiting_tasks
Resolve Blocking Session:- (1) Right click on session and Kill in Activity
Monitor (2) Kill Session_id
18) What is Deadlock?

A deadlock occurs when users try to place exclusive locks on each others
Ex:- User1 places an exclusive lock on Table1 and then tries to place an
exclusive lock on Table2. User2 already has an exclusive lock on table2, and
User2 tries to put an exclusive lock on Table1. This condition causes endless
loop of waiting for the locks to be released.
The Database engine picks one of the victim (users) and kills their
query and send a error message to users You are the victim of a deadlock
and try again later.
Deadlock Information Tools
1) Trace Flags:- DBCC TRACEON (1204) & DBCC TRACEON (1222). When
these trace flags is enabling, the deadlock information captured by the
SQL Server error log.
2) Deadlock graph event in SQL Profiler:- SQL Server Profiler graphically
representation of tasks and resources involved in a deadlock.
(Lock:Deadlock and Lock:Deadlock chain events in the Locks events)
3) System View:- We can find the blocking sessions by writing the following
Select session_id, status, blocking_session_id from sys.dm_exec_requests
where blocking_session_id > 0
Resolving Deadlock:- After find the session causing the problem we can
use KILL command.
> KILL process_id
19) What are the Types of Locks? Explain each?
There are 7 locks types are available in SQL Server 2005.
a) Shared Lock:- Shared (S) locks allow concurrent transactions to read
(SELECT) a resource under pessimistic concurrency control.
b) Update Lock:- Used on resources that can be updated. Prevents a
common form of deadlock that occurs when multiple sessions are reading,
locking, and potentially updating resources later.
c) Exclusive Lock:- Exclusive (X) locks prevent access to a resource by
concurrent transactions
d) Intent Lock:- Used to establish a lock hierarchy. The types of intent locks
are: intent shared (IS), intent exclusive (IX), and shared with intent
exclusive (SIX).
e) Schema:- Used when an operation dependent on the schema of a table is
f) Bulk Update:- Used when bulk copying data into a table and the
TABLOCK hint is specified
g) Key-Range:- Protects the range of rows read by a query when using the
serializable transaction isolation level
What are the Components can be installed with SQL Server
We can install the following components with Microsoft SQL Server 2005
a) SQL Server Database Engine
b) Analysis Services
c) Reporting Services
d) Notification Services

e) Integration Services
f) Management Tools
g) Documentation and Samples

What are the SQL Server Editions of SQL Server 2005?
SQL Server 2005 is available in 32-bit and 64-bit editions.
a) SQL Server 2005 Enterprise Edition (32-bit and 64-bit)
b) SQL Server 2005 Evaluation Edition (32-bit and 64-bit)
c) SQL Server 2005 Standard Edition (32-bit and 64-bit)
d) SQL Server 2005 Workgroup Edition (32-bit only)
e) SQL Server 2005 Developer Edition (32-bit and 64-bit)
f) SQL Server 2005 Express Edition (32-bit only)
g) SQL Server 2005 Compact Edition (32-bit only)
h) SQL Server 2005 Runtime Edition (32-bit and 64-bit)
What is the process of Installation?
a) Prepare Your Computer to Install SQL Server 2005:- To prepare your
computer for SQL Server 2005, review hardware and software
requirements, System Configuration Checker requirements and blocking
issues, and security considerations.
b) Install SQL Server 2005:- To install SQL Server 2005, run Setup using
the SQL Server 2005 Installation Wizard or install from the command
prompt. You can also add components to an instance of SQL Server 2005,
or upgrade to SQL Server 2005 from a previous SQL Server version.
c) Configure Your SQL Server 2005 Installation:- After Setup completes
the installation of SQL Server 2005, you can configure SQL Server using
graphical and command prompt utilities
What is the Virtual Memory? How to assign virtual memory &
how much space required for Virtual memory?
A reserved disk space to maintain transactions whenever Memory (RAM) is
full. Virtual memory size is at least 3 times of the physical memory installed
in the computer.
To Set Virtual memory:- Right click on System > Select System Properties
> Advanced > Performance Settings > Advanced > Virtual memory >
Change > Select directory > Provide min and max values.
1) What is Database? What are the files created while creating a
A Database is a collection of meaningful and related data that are stored in row
and columns format (Tables). While creating a Database in SQL Server there are
two data files are created called master data file (.mdf), log data file (.ldf) and
we can add one or more optional N-Dimensional data files (.ndf).
2) Explain about Data files (.mdf, .ndf, .ldf) (File structure)?

a) Primary Data file (.ldf):- Primary data files holds user data and objects.
Every database has one primary data file.
b) Secondary Data file (.ndf):- Secondary Data file (.ndf) is optional and hold
user data and objects that do not fit in the Primary data file. We can add N no.
of Secondary data files for a DB.
c) Log Data file (.ldf):- T.Log records all the transactions and database
modifications made by each transaction and it is used to recover the
database. At least one transaction log file required for each DB. Min. log file
size is 512 KB.
3) How store the data in SQL Server? What is Page and Page size? What is
Extent and Extent size?
The fundamental unit of data storage in SQL server is the PAGE. The size of the
page is 8 kb. Collection of eight contiguous pages is known as an EXTENT. The
size of an extent is 64 kb (8x8).
4) What is Fill factor? How to assign Fill factor?
A Fill factor is a reserved free space on each leaf level page which is used for
future growth of data or index in a table and reduces the page splits.
Assign Fill Factor:- Right Click on Server > Properties > Database Settings >
Default Index Fill Factor > Provide the value
5) Tell me about System Database and User Databases in 2000 and 2005?
SQL Server 2000:- 1) Master 2) Model 3) MSDB 4) TempDB
SQL Server 2005:- 1) Master 2) Model 3) MSDB 4) TempDB 5) Resource DB
6) Explain about System Databases in SQL Server 2005?
There are five system databases available in SQL Server 2005.
a) Master Database:- Records Server level objects such as Login Accounts, End
Points, Linked Servers, System Configuration settings, location of the
database files and initialization information for SQL server. SQL Server Cannot
starts if Master DB is unavailable.
b) Model Database:- The Model DB is used as a template for all databases
created on instances of SQL Server. If we create a new Database the Model
DB structure will be inherited to new Database.
c) MSDB Database:- The msdb database is used by SQL Server Agent for
scheduling alerts and jobs and by other features such as Service Broker and
Database Mail. SQL Server automatically maintain completed online backup
and restore history in MSDB.
d) TempDB:- Temp DB is a global resource DB. It stores user objects (global or
local temporary tables, stored procedures, table variables, or cursors),
Internal objects (intermediate results for spools or sorting) and versions
(online index operations, Multiple Active Result Sets (MARS), and AFTER
triggers). We cannot backup the Temp DB because when SQL Server Start (or)
Stop the Temp DB can be deleted permanently (or) refresh Temp DB.
e) Resource Database :- The Resource database is a hidden (read-only)
database that contains all the system objects such as sys.objects that are
included with SQL Server 2005. The Resource database makes upgrading
process easier and faster.

7) If Model and MSDB Database will crash what

rebuild Master Database?
We can re-create Model and MSDB databases
SQL Server 2000 (Rebuild MasterDB):- Start >
SQL Server 2005 (Rebuild MasterDB):- Start >

you will do? How to

by rebuild the Master
Run > rebuildm.exe
Run > setup.exe

8) How to move Model, MSDB, TempDB?

a. Check the Path of TempDB through sp_HelpDB TempDB
c. Stop the Services
d. Move the files to desired location
e. Restart the Services
f. Check the Path of TempDB through sp_HelpDB TempDB
9) How to move Master Database?
a. Check the Path of Master DB through sp_HelpDB Master
b. Stop the Services
c. Change the path at Startup parameters
SQL Server Configuration manager > Services > Right click on Service >
Properties > Advanced > Add new_path at Startup parameters
d. Move the files to desired location
e. Restart the Services
f. Check the Path of Master DB through sp_HelpDB Master
10) What are the Database States and explain them?
The main database states are online, offline, restoring, recovering, resource
pending, suspect and emergency.
11) What is Database Snapshot? Give the Syntax?
A Database snapshot is a read-only static view of the database. Snapshots must
be located on the same server. Snapshots doesnt contain un-committed
transactions at the time of snapshot was taken. It is very useful for report
queries. (This option is available in 2005 EE edition)
Ex:- CREATE DATABASE AdventureWorks_dbss1800 ON ( NAME =
AdventureWorks_Data, FILENAME = 'C:\Program Files\Microsoft SQL
12) What is Transaction? What is Transaction (ACID) Properties?
Transaction is a set of Logical unit of work and it contains one or more database
operations. A valid transaction should be met (ACID) Atomicity, Consistency,
Isolation, Durability properties.
a) Atomicity:- A transaction must be an atomic unit of work, either all of it data
modification are performed (or) none of them is performed.
b) Consistency:- When completed a transaction must leave all data in
consistent state. In a relational database, all rules must be applied to
transactions modifications to maintain all data integrity. All internal data

structures, such as B-tree indexes (or) double linked lists must be correct at
end of transaction.
c) Isolation:- Modifications made by concurrent transactions must be isolated
from the modifications made by the other consequent transactions. A
transaction either sees a data in the state it was in before another concurrent
transaction modified it, (or) sees the data after second transaction
d) Durability:- After a transaction has completed, its effects are permanently in
place in the system. The modification persists even in the event of a system

13) What are Transaction Isolation levels?

An Isolation level determines the degree of isolation of data between concurrent
transactions. The default isolation level is Read committed.
a) Read uncommitted
b) Read committed
c) Repeatable read
d) Serializable
14) What is purpose of LSN numbers?
Every record in the transaction log is uniquely identified by a log sequence
number (LSN). LSNs are used internally during a RESTORE sequence to track the
point in time to which data has been restored.
15) Explain about RAID and RAID levels?
RAID stands for Redundant Array of Independent Disks. RAID is a disk system
that contains arrays to provide greater performance, reliability, storage
capacity, and lower cost. Typically 0, 1, and 5 RAID levels are used in SQL
16) If a Database in Single User mode? How to change into Multi-user
Alter database <database name> set multi_user
17) Minimal Mode and Single user mode?
Minimal mode: - Start ->run -> command prompt > SQLSERVER.EXE f
Single user mode: - Start ->run -> command prompt > SQLSERVER.EXE m
18) Orphaned Users? How to find Orphaned Users and Resolve them?
When a DB is move, attach & detach, restoring to different instance or
corresponding login is dropped, the users of the Database becomes Orphaned
users and they cant access the database because the database users are not
mapped to SID (Security Identifier) in the new instance.
To detect Orphaned users:- sp_change_users_login 'Report'
To Resolve Orphaned Users:- sp_change_users_login 'Update_One',
'db_user', 'login_name'

What is Row size of a Database?

Row size of a database is 8060 bytes.

20) What is Heap table?
A table without a clustered index is called as heap table.
21) What is Check point?
Check Point is a operations that synchronizes the physical data with the current
state of the buffer cache by writing out all modified data pages in buffer cache
to disk.
22) How many ways you can move the data or databases between
servers and databases?
SSIS, DTS, Attach & Detach, Bulk copy program, Bulk Insert & Import and Export
23) Syntax for find out the Database ID?
Select db_id (db_name)

Syntax for find out Logins? Current User?

To find out logins: - select * from sys.syslogins
To find out current user:- Select current_user


Is it possible to take Backups and Restores of System Databases?

Recovery Models
1) What is Recovery Model? Benefits of Recovery Models?
A recovery model is a Database property that control the basic behavior of
the backup and restore operations for a DB. Recovery models are designed
to control transaction log maintenance.
2) Explain Full, Bulk-Logged & Simple Recovery Models?
a) Full:- With Full Recovery Model we can recover the data up to the minute
of crash, because it records every operation in the transaction log.
a) Bulk-Logged:- With Bulk-Logged recovery model we can recover most of
the data, but we will lost bulk-operations because those are not recorded
in to the log. We can set this option just before performing a bulk insert
operation to speed up the bulk insert.
b) Simple:- With Simple Recovery Model we can recover the data only up to
the last backup, because nothing is recorded in the transactional log. Any
changes made to database after the last backup was performed will be lost
because they are not recorded in the transaction log. Generally it is useful
for test and development databases or data warehouses, but it is not
appropriate choice for Production Database.
3) Which DBs can we use Simple Recovery Model?
Simple Recovery Model is useful for Development, Test databases, Data
warehouses or not often changed Databases.
4) In Which Recovery Models Point-in-time recovery is possible?


Point-in-Time Recovery is Possible only in Full and Bulk-Logged Recovery

Models. But in Bulk-Logged Recovery model Point-in-time recovery is may or
may not possible.
5) In System DBs what are the default Recovery Models used?
- Simple
- Full
- Simple
- Simple
6) Why in Simple Recovery model we cant take T.Log backups?
In Simple Recovery Model the Transaction Logs are truncated.
7) Can we take Diff. backup in Simple recovery Model?
We can take Differential backup in Simple recovery model because it belongs
to .mdf
1) What is Backups? Types of backups?
A copy of data that is used to restore and recover the data after a system
failure. There are four types of Backups available (1) Full Backup (2)
Differential Backup (3) Transaction Log Backup (4) File /File Group Backup
2) What is Use of Backups?
Backups is Safe Guard to Databases because Data may can loss due to many
failures such as Media Failures, User errors, Hardware Failures and Natural
Disasters etc. With good backups, we can recover database from failures.
3) What is Full, Diff, T.Log Bakups? Explain Each?
a) Full Backup:- Full backup, backs up the entire Database including
Transaction Log. With full Backup Point-in-time recovery is possible
because it contains .mdf and .ldf. It offers complete protection against
media failures.
b) Differential Backup:- Differential backup records only the data that has
change or modified extents since the last full backup.
c) T.Log Backup:- Transaction Log that records all transactions since last
transaction log backup or differential backup. It can be used for recover
the data to the point of failure (or) specific point-in-time
d) File/File Group backup:- File and File group backups are a specialized
form of DB backup. In which only certain individual file (or) file groups
from a DB are backup.
4) Can we take Diff. backups without Full backups?
No, it is not possible.
5) What are the Syntaxes for Backups?
a) Full Backup: - Backup database dbname to disk = path
b) Diff. Backup: - Backup database dbname to disk = path with


c) T.Log Backup:- Backup log dbname to disk = path

6) Explain about Tail of Log? Give the syntax?
The tail-log backup is the last backup that have not been backed up earlier,
to recover the database to the point of a failure. (A backup taken that have
not been backed up just before restoring a database).
Syntax :1) BACKUP LOG database_name TO <backup_device> WITH
2) BACKUP LOG database_name TO <backup_device> [WITH
7) Backups strategy?
Generally Backups are done by client requirement. But Most of the
companies are following this strategy.
1) Full Backup:- Every Saturday evening 6.00 PM
2) Differential Backup:- Every Day evening 6.00 PM
3) Transactional Log Backup:- Every one hour
1) What is Restore? What are the recovery states? Explain Each?
Restore means recover the data from backups. There are three recovery
states for Restore. (1) With Recovery (2) With No-Recovery (3) Standby.
a) With Recovery:- With Recovery, Database will comes to Online and get
ready to using Database. Generally while restoring recent (last) T.Log we
can choose with recovery option.
b) With No-Recovery:- With No-Recovery Databases will comes to Offline
and we cant access DB. Generally except recent log we can choose With
No-Recovery option.
c) Standby:- With Standby, Databases will comes to Offline and users can
have read only access. Generally except recent log we can choose Standby
option for Read only access.
2) What are the common scenarios to Restoring the Data?
1) To restore the lost and corrupted data after a system failure
2) To restore a database onto a development system for user by application
developers while developing and testing new code.
3) To restore a database onto a test system to load test applications and
database features.
4) To restore a database on separate server as a read-only database to
perform queries for reports.
3) In which edition On-line restoration is possible?
On-line restoration is possible only in Enterprise edition.
4) What are the Syntaxes for Restore?
a) With Recovery:-Restore database dbname from disk = Path with
b) With No-Recovery:- Restore database dbname from disk = Path with
no recovery
c) Standby:- Restore database dbname from disk = Path with no standby


5) What is Point-in-time restore and use of that?

Point-in-time restore is used to restore the Database to a particular time just
before a failure has occurred or before corrupt data.
6) Explain about STOPAT clause?
STOPAT clause is used to restore a data base at point of time.
7) Restore Strategy?
1. First restore recent last full backup
2. Then restore last Diff. backup
3. Then restore all Transaction Log backups.

1) What is Log shipping and purpose of Log shipping?
To achieve high availability and high protection, Log shipping copies
transactions from a primary server to one or more secondary servers. In Log
shipping, T.Log backups are sent to one or more secondary servers and then
restored to the destination servers individually. If the Primary database
becomes unavailable, any of the secondary database can brought into online
manually. The Secondary server acts as a Backup server and provides read-only
query processing to reduce the load on the Primary server. (For query
processing, secondary servers should be configure in stand-by mode).
2) What is Primary Server, Secondary Server & Monitor Server?
a) Primary Server: - Primary Server is a Production server which holds the
original copy of the database. Log shipping configuration and administrating
will be done from Primary Server.
b) Secondary Server: - Secondary servers hold the standby copy of the
database. We must initialize the DB on a secondary server by restoring a
backup from the Primary server using either NORECOVERY option or the
STANDBY option. By using STANDBY option Users can have read-only access
to it.
c) Monitor Server: - An optional Server is called as Monitor Server that
records history and status of backup, copy and restore operations and raises
alerts if any operations fail. The Monitor Sever should be on separate server
to avoid losing critical information. Single Monitor Server monitors multiple
Log shipping configurations.
3) What are the Jobs running for Log shipping and explain them?
Log shipping having four operations which are handled by SQL Server Agent Job.
a) Backup Job: - Backup job is created on Primary Server instance and it
performs backup operation. It logs history on the local server and monitor
severs and deletes old backup files and history information.
b) Copy Job: - Copy Job is created on Secondary server instance and it performs
copies the backup files from primary sever to secondary server. It logs history
on the secondary server and monitor server.


c) Restore Job: - Restore Job is created on the Secondary server instance and it
performs restore operation. It logs history on the local server and monitor
sever and deletes old files and history information.
d) Alert Job: - If a Monitor Server is used, the Alert Jobs is created on the
Monitor server instance and it raises Alerts if any operations have not
completed successfully.
4) Requirements for Log shipping?
a) SQL Server 2005 Standard Edition, Workgroup Edition, or Enterprise Edition
must be installed on all server instances involved in log shipping.
b) All servers should have the same case sensitivity settings.
c) The databases must use the full recovery model or bulk-logged recovery
5) How to configure Log shipping?
a. Choose Primary Server, Secondary Servers, and optional Monitor server.
b. Create a File share to keep Transaction log backups (Best to place on a
separate computer)
c. Create a folder for each Secondary server into which transaction log backup
d. Choose Backup Schedule for Primary Database
e. Choose Copy and Restore Schedules for Secondary Database
f. Choose Alert Job schedule for Monitor Server if configured
6) What are permissions required for Log shipping?
We must have sysadmin on each server instance to configure Log shipping.
7) In Logshipping which Recovery Models can we used?
We can use either full or bulk logged recovery model for log shipping.
8) Where you monitoring Log shipping and how?
We can monitoring the Log shipping in the following ways.
a) Monitor server (History Tables):- Monitor Server tracks all statistics, status
and errors that could be happen during Log shipping.
1) Log_shipping_monitor_primary:- Stores primary server status
2) Log_shipping_monitor_secondary:- Stores secondary servers status
3) Log_shipping_monitor_history_detail:- Contains history details for
logshipping agents.
4) Log_shipping_monitor_error_detail:- Stores error details for log shipping
5) Log_shipping_monitor_alert:- Stores Alert Job ID
b) System Stored Procedures (MSDB):- System Stored procedures gives the
history information about the specified server that are configured in Log
1) sp_help_log_shipping_monitor (Run at Monitor Server)
2) sp_help_log_shipping_monitor_primary @Primary_Database = DBName
(Run at MS)
3) sp_help_log_shipping_monitor_secondary
DBName (Run at MS)


4) sp_help_log_shipping_alert_job (Run at Mon Server)

5) sp_help_log_shipping_primary_database @ Database = DBName (Run at
Primary Server)
6) sp_help_log_shipping_secondary_database @ Database = DBName (Run
at Sec Server)
c) Transaction Log shipping Status report (Summary Reports):- This
report shows the status of log shipping configurations for which this server
instance is a primary, secondary or monitor.
d) SQL Server Agent Job History
e) Checking the SQL Server Log
9) How Secondary Server will brought into Online, if the Primary Server
becomes Unavailable?
If the Primary Server will become un-available, do the following steps.
a) Take the Tail of Log from Primary server
b) Restore Tail of log into all Secondary Database
c) Remove Log-shipping configuration from Primary Server
d) Select any one of Secondary server and bring into online with Alter Database
DBName set Online
e) Right click on Primary Database and Generate script for Users and Logins.
f) Then move the script to Secondary server to create Users and Logins
g) Re-configure log shipping from New Server (Secondary server)
10) What are errors occurred in Log shipping?
There are two errors are occurred during Log shipping
1) 14420:- This error occurs when the Backup job fails
2) 14421:- This error occurs when the Restoring job fails
1) What is Database Mirroring? What are the benefits of that?
Database mirroring is a method of increasing database availability, which
supports automatic failover with no loss of data.
Benefits:h) Increases data protection
i) Increases availability of a database
j) Improves the availability of the production database during upgrades
2) What are the prerequisites for Database Mirroring?
a) Both Servers are requires same edition either Standard Edition or
Enterprise Edition.
b) If Witness server configured, the server should be installed Standard
Edition, Enterprise Edition, Workgroup Edition, or Express Edition.
c) All Servers should use the same master code page and collation.
d) Mirror Server has same database name and use only With NoRecovery
e) Mirroring uses the full recovery model. (Simple and bulk-logged not
f) All logins for connecting Principal Database should be reside on Mirror


3) What are the Restrictions for Database Mirroring?

a) Maximum 10 databases per instance can support on a 32-bit system.
b) Database mirroring is not supported with either cross-database
transactions or distributed transactions.
4) Explain about Principal, Mirror and Witness Servers?
1) Principal Server:- One Server serves the database to client is called
Principal server and it having original data. Can have only one Principal
Server and it has to be on a separate server.
2) Mirror Server:- Other server instance acts as a hot or warm standby
server is called Mirror server and it having copy of database.
3) Witness Server:- The witness server is an optional server and it controls
automatic failover to the mirror if the principal becomes unavailable. To
support automatic failover, a database mirroring session must be
configured in high-availability.
5) In which Operations are running the Operating Modes?
Asynchronous:- Under asynchronous operation, the Principal server does
not wait for a response from the mirror server after sending the log buffer.
Synchronous:- Under synchronous operation, the Principal server sends the
log buffer to the mirror server, and then waits for a response from the mirror
6) What are the Operating Modes and explain them?
a. High Availability:- High-availability mode, runs synchronously. Requires
a Witness Server instance. The Principal server sends the log buffer to the
mirror server, and then waits for a response from the mirror server.
b. High Protection:- High-protection mode, runs synchronously. Always
commit changes at both the Principal and Mirror.
c. High Performance:- High-performance mode, runs asynchronously and
the transaction safety set to off. The Principal server does not wait for a
response from the mirror server after sending the log buffer. The principal
server running nice and fast, but could lose data on the mirror server.
7) What is the default of Port numbers of Principal and Mirror servers?
How to find the Port numbers?
The default port numbers of principal and mirror servers are 5022 and 5023.
To Find Port Number:- SELECT name, port FROM sys.tcp_endpoints
8) What is End Point? How u create end point?
An endpoint is a network protocol which is used to communicate over the
Creation of an end point:
Create endpoint <endpoint name> State=started/stopped/disabled
9) Which Trace flag is used in Mirroring?


Trace flags are used to temporarily set specific server characteristics or to

switch off/on a particular behavior. 1400 Trace flag is used in mirroring.
To set trace flag for Database mirroring:- Configuration Manager >
Right click on server instance > Properties > Advanced tab > Startup
parameters > -t1400 (add)
In which Recovery model we can use in Mirroring?
In mirroring the principal and mirror databases are used only full recovery
What is Role-switching?
Inter changing of roles like principal and mirror are called role switching.
What is the Syntax to stop the Database Mirroring?
Alter database <database name> set partner off
How to configure Mirroring?
a) Choose Principal Server, Mirror Server, and optional Witness server.
b) The principal and mirror server instances must be running the same
edition either Standard Edition or Enterprise Edition
c) The Witness server instance can run on SQL Server Standard Edition,
Enterprise Edition, Workgroup Edition, or Express Edition
d) Mirror database requires restoring a recent backup and one or more T.log
backups of the principal database (with Norecovery)

How to monitoring Mirroring?
There are six methods are available for monitoring the Database Mirroring
a) SQL Server Management Studio:- A green arrow on the mirror server is
indicates running well. A red arrow indicates problems that need to
b) SQL Server Log:- It provides information of Mirroring establishment and
status. If any errors occurs it will be logged to SQL Server log and Windows
event log.
c) Performance Monitor:- It can provides real-time information about
Database mirroring. We can use performance counters to get status of the
database mirroring such as Bytes received/sec, Bytes sent/sec, Transaction
delay etc.
d) Profiler:- Profiler many events are providing the status of the Database
e) Database Mirroring Monitor:- Database Mirroring Monitor is a GUI tool
that shows update status and to configure warning thresholds.
To open DM Monitor:- Right click on Principal Database > Tasks > Select
Launch Database Mirroring Monitor.
f) System Stored Procedures:2. sp_dbmmonitoraddmonitoring
3. sp_dbmmonitorchangemonitoring
4. sp_dbmmonitorhelpmonitoring
5. sp_dbmmonitordropmonitoring


What is Hardening?
As quickly as possible, the log buffer is written to the transaction log on disk,
a process called hardening.
What is Log buffer
A log buffer is a special location in memory (RAM). SQL Server stores the
changes in the databases log buffer.
How to Set a Witness Server to Database Mirroring?
SSMS:- Right Click on Principal Database > Tasks > Mirror > Click on
Configure Security > Provide the End point for Witness server > Click oK
'TCP://prasad.local:5024' (Do this from the Principal Server)
How to Remove a Witness Server from Database Mirroring?
SSMS:- Right Click on Principal Database > Tasks > Mirror > Remove TCP
address from the Witness > Click oK
How to Setup Fully Qualified Names for Database Mirroring?
I. FQDN Error
One or more of the server network addresses lacks a fully qualified domain
name (FQDN). Specify the FQDN for each server, and click Start Mirroring
The syntax for a fully-qualified TCP address is:


1) To View Endpoints:-SELECT * FROM sys.database_mirroring_endpoints;
2) Remove existing all Endpoints from Principal, Mirror and Witness
3) Adding "local" as the primary DNS suffix as follows:a) Right-click My Computer, and then click Properties. The System
Properties dialog box will appear.
b) Click the Computer Name tab.
c) Click Change. The Computer Name Changes dialog box will appear.
d) Click More. The DNS Suffix and NetBIOS Computer Name dialog
box will appear.
e) Enter the appropriate DNS suffix for the domain.
f) Select the Change primary DNS suffix when domain membership
changes check box.
g) Click OK to save the changes, and then click OK to exit the Computer
Name Changes dialog box.
h) Click OK to close the System Properties dialog box, and then restart
the computer for the change to take effect.
4) Reconfigure the Database mirroring either GUI or T-SQL



What are the Database Mirroring states?

SYNCHRONIZING:The contents of the mirror database are lagging behind the contents of
the principal database. The principal server is sending log records to the
mirror server, which is applying the changes to the mirror database to roll
it forward.
At the start of a database mirroring session, the database is in the
SYNCHRONIZING state. The principal server is serving the database, and
the mirror is trying to catch up.
SYNCHRONIZED:When the mirror server becomes sufficiently caught up to the principal
server, the mirroring state changes to SYNCHRONIZED. The database
remains in this state as long as the principal server continues to send
changes to the mirror server and the mirror server continues to apply
changes to the mirror database.
If transaction safety is set to FULL, automatic failover and manual
failover are both supported in the SYNCHRONIZED state, there is no data
loss after a failover.
If transaction safety is off, some data loss is always possible, even in


SUSPENDED:The mirror copy of the database is not available. The principal

database is running without sending any logs to the mirror server, a
condition known as running exposed. This is the state after a failover.
A session can also become SUSPENDED as a result of redo errors or if
the administrator pauses the session
SUSPENDED is a persistent state that survives partner shutdowns and


PENDING_FAILOVER:This state is found only on the principal server after a failover has
begun, but the server has not transitioned into the mirror role.
When the failover is initiated, the principal database goes into the
PENDING_FAILOVER state, quickly terminates any user connections, and
takes over the mirror role soon thereafter.
DISCONNECTED:The partner has lost communication with the other partner
What is Replication?
Replication is the process of copying and distributing data between databases
to different servers throughout the enterprise.
Replication is a set of technologies for copying and distributing data and
database objects from one database to another and then synchronizing between
databases to maintain consistency.

What are the uses of Replication?


a) Server to Server Replication:1. Improving scalability and availability

2. Data warehousing and reporting
3. Integrating data from multiple sites
4. Integrating heterogeneous data
5. Offloading batch processing
b) Server to Client Replication:1. Exchanging data with mobile users
2. Retail point of sale (POS) applications
3. Integrating data from multiple sites
Types of Replication and explain each?
a) Snapshot replication:- Snapshot replication takes a picture or a snapshot of
the database and propagated to the subscribers. It reduces the overhead on
the Publishers and Subscribers because it does not monitor data updates.
Snapshot replication is very useful, when the source data is changes
occasionally (Reporting).
b) Transactional replication:- Transactional Replication starts with a snapshot
of the publisher database. With Transactional Replication, any changes made
to the articles are captured from the transactional log and propagated to the
distributors continuously and automatically. Using Transactional Replication we
can keep the publisher and subscriber in almost exactly the same state.
c) Merge replication:- Merge Replication starts with a snapshot of the publisher
database. Subsequent data changes and schema modifications made at the
Publisher and Subscribers are tracked with triggers. The Subscriber
synchronizes with the Publisher when connected to the network and
exchanges all rows that have changed between the Publisher and Subscriber
since the last time synchronization occurred.

Explain about Publisher, Subscriber and Distributer?
a) Publisher:- The Publisher is a database that makes data available for
replication. The Publisher can have one or more publications.
b) Distributor:- The distributor is the intermediary between the publisher and
subscriber. It receives published transactions or snapshots and then stores and
forwards these publications to the subscribers.
c) Subscribers:- Subscribers are database servers that store the replicated
data and receive updates. A subscriber can receive data from multiple
publishers. Based on the replication type, the Subscriber can also pass data
changes back to the Publisher or republish the data to other Subscribers.
Explain about Article, Publication, Subscription?
a) Article:- An Article is the data, transactions, or stored procedures that are
stored within a publication. This is the actual information that is going to be
b) Publication:- The publication is the storage container for different articles. A
subscriber can subscribe to an individual article or an entire publication.


c) Subscription:-Subscription is a request by the subscriber to receive the

Which recovery models are used for Replication?
Full and Bulk-logged Recovery models
How to monitor the Replication?
a) Replication Monitor:- Replication Monitor is a GUI tool provides detailed
information on the status and performance of publications and subscriptions.
By using replication monitor we can find out (1) which subscriptions are slow
(2) Why is an agent not running (3) Time taken to transaction commit (4) Why
merge replication is slow (5) How far behind subscription etc.
To launch Replication Monitor :- Connect Instance > Right Click on
Replication folder > Select launch Replication monitor
b) Management Studio:- By using management Studio we can see View
Snapshot Agent Status, View Log Reader Agent Status, View Synchronization
Status etc.
Through SSMS:- Connect Instance > Right Click on Publication > Select the
c) System Monitor:- Provides information on the performance of various
processes of Replication.
All agents
Snapshot: Delivered
Snapshot: Delivered
Log Reader
Logreader: Delivered
Log Reader
Logreader: Delivered
Log Reader
Logreader: Delivery
Replication Dist.
Dist: Delivered Cmds/sec
Replication Dist.
Dist: Delivered Trans/sec
Replication Dist.
Dist: Delivery Latency
Merge Agent
Replication Merge Conflicts/sec
Merge Agent
Replication Merge
Merge Agent
Replication Merge Uploaded Changes/sec
8) What are the Agents available for Replication and explain each?
SQL Server Agent hosts and schedules the agents used in replication and also
controls and monitors operations outside of replication.


b) Snapshot Agent:-The Snapshot Agent is typically used for all types of

replication. It is responsible for copying the schema and data from the
publisher to the subscribers, stores the snapshot files, and records
information about synchronization in the distribution database. The Snapshot
Agent runs at the Distributor.
c) Log Reader Agent:- The Log Reader Agent is used for transactional
replication. It moves information from the transaction log on the publisher to
the distribution database.
d) Distribution Agent:- The Distribution Agent is used for snapshot replication
and transactional replication. It is responsible for moving the stored
transactions from the distributor to the subscribers.
e) Merge Agent:- The Merge Agent is used for merge replication. It is
responsible for converging records from multiple sites and then redistributing
the converged records back to the subscribers.
f) Queue Reader Agent:- The Queue Reader Agent is used for transactional
replication with the queued updating option. It runs on the Distributor and is
responsible for reading messages from the queue on the subscribers and
applying them to the appropriate publication.
9) What are the Agents used for Transactional Replication?
a) Snapshot Agent
b) Log Reader Agent
c) Distribution Agent
10) What are the Agents used for Merge Replication?
a) Snapshot Agent
b) Merge Agent
11) What is the Process of Transactional Replication?
Three Agents are doing the Process for Transactional Replication

What is Maintenance Plan?
Maintenance plans create a workflow for database optimization, and make free
from inconsistencies.
2) What the tasks in Maintenance Plans?
3) SQL Server Logs?
Database Mail?
Database Mail is an enterprise solution for sending e-mail messages from the
Microsoft SQL Server 2005 Database Engine. Using Database Mail, your database
applications can send e-mail messages to users. The messages can contain


query results, and can also include files from any resource on your network.
Database Mail is designed for reliability, scalability, security, and supportability.
5) Full Text Search?

1) Which Tools are used for Performance Tuning?
There are many tools are used for Performance tuning
a) Windows tools for monitoring applications:- Performance monitor,
Performance Counters and Logs, Task manager, Network manager
b) SQL Server tools for monitoring components:- SQL trace, SQL
Profiler, DMVs, System Stored procedures, Graphical show plan, Activity
Monitor, DBCC, Built-in Functions, Trace flags
2) How to identify longest running queries?
There are two ways to identify slow running queries
1) Profiler (By using duration of the query)
2) sys.dm_exec_query_stats and sys.dm_exec_requests DMVs
3) Reasons for Slow Running Query?
There are a number of common reasons for slow-running queries
a) Lack of useful indexes, Lack of useful data striping (RAID).
b) Blockings, Table scans, Lack of useful partitioning
c) Missing or out of date statistics (update statistics)
d) Slow network communication.
e) Insufficient memory available for SQL Server.
f) Insufficient disk space.
g) Excess recompilations of Stored Procedures
h) Procedures and Triggers without SET NOCOUNT On
4) How to analyze query performance?
We can analyze query performance in three ways
2) SSMS:- Estimated Execution Plan & Actual Execution plan
3) Profiler:- To display text and XML execution plans, see Displaying
Execution Plans by Using SQL Server Profiler Event Classes
5) How to increase Query performance?
We can improve query performance in the following ways
1) Add indexes if required
2) Run Update statistics for out of date statistics
3) Resolving Blocking issues
4) Add space to DB files or TempDB, if that are not having enough space
5) Reduce the too much normalization
6) Using Temporary tables instead of Cursors
7) SPs and Triggers are with Set NOCOUNT On


8) Unnecessarily complicated joins

6) Explain about Profiler? What are the Uses of Profiler?
SQL Profiler can capture SQL Server events from the server to analyze or
troubleshoot performance problems such as Finding Slow-running queries
and Monitoring performance etc. Profiler is useful for maintaining security,
troubleshooting, monitoring and optimization.
Uses of SQL Profiler:a) Find the worst-performing queries.
b) Identify the cause of a deadlock.
c) Monitor stored procedure performance
d) Audit SQL Server activity.
e) Monitoring T-SQL activity per user.
f) Collect a representative sample of events for stress testing.
g) Collect a sample of events for tuning the physical database design by
using Database Engine Tuning Advisor.
7) What are the Events is captured SQL Profiler?
We can capture the events such as
a) T-SQL Statements, Stored Procedures
b) Cursors, Locks (deadlocks)
c) Databases objects and auto growth of size of data & log files
d) Errors & warnings (syntax errors)
e) Performance (show plan)
f) Table Scans
g) Security audits (failed logins, password changes)
h) Monitor server control, memory changes (CPU, Reads, Writes)
i) Sessions, Transactions, Tuning

8) Explain about Database Tuning Advisor? What is Workload?

Database Tuning Advisor can analyze the performance effects of workloads
run against one or more Databases or a SQL Profiler trace (they may contain
T-SQL batch or remote procedure call). After analyzing, it recommends to
add, remove or modify physical design structures such as clustered and nonclustered indexes, indexed views and partitioning.
Workload:- A workload is a set of Transact-SQL statements that executes
against databases you want to tune
9) What is Dynamic Management Views?
DMVs return server state information that we can use to monitor the health
of a server instance, diagnose problems, and tune performance. There are
two types of DMVs:
a) Server-scoped DMVs:- Require the VIEW SERVER STATE permission on
the server.
b) Database-scoped DMVs:- Require the VIEW DATABASE STATE
permission on the database.


What is DAC? How to connect DAC?
DAC is stands for Dedicated Administrator Connection. This diagnostic
connection allows an administrator to access running instance to
troubleshoot problems or execute diagnostic queries on the server - even
when SQL Server is not responding to standard connection requests. This
connection uses 1434 port and can connect only one connection per
To connect DAC:1) SQLCMD:- -Sadmin:<instance_name>
2) GUI:- SSMS Query Editor by connecting to ADMIN:<instance_name>
Explain about Database Console Commands (DBCC)?
DBCC Commands are used to check the consistency of the Databases or
Database Objects. While executing DBCC commands the DB engine creates a
database snapshot and then runs the checks against this snapshot. After the
DBCC command is completed, this snapshot is dropped.
12) What is Stored Procure? What are the types of stored Procedures
available in SQL server and explain each?
A stored procedure is a precompiled executable object that contains one
or more Transact-SQL statements.
a) User Defined Stored Procedure:- Stored procedures are modules or
routines that encapsulate code for reuse. A stored procedure can take
input parameters, return tabular or scalar results and messages to the
b) System Stored Procedure:- System stored procedures are used to
perform many administrative and informational activities.
c) Extended stored procedure:- Extended stored procedures are used to
create own external routines in a programming language such as C.
Extended stored procedures are DLLs that an instance of Microsoft SQL
Server can dynamically load and run.
13) What is Activity Monitor and use of that? What are the permissions
required to use Activity Monitor?
Activity Monitor is used to get information about users connections to the
Database Engine and the locks that they hold. Activity Monitor is used to
troubleshooting database locking issues, and to terminate a deadlocked or
unresponsive process.
To use activity monitor:- VIEW SERVER STATE permission on Server
and SELECT permission to the sysprocesses & syslocks tables in the
master database.
To Kill a Process:- sysadmin and processadmin database roles and
permission are required to KILL a process.
14) What is Execution Plan and explain it?
Execution Plan graphically displays the data retrieval methods chosen by
SQL Server. It represents the execution cost of specific statements and
queries in SQL Server. This graphical approach is very useful for
understanding the performance of the query.


21) What is Trace flag? Give some Trace flags?

Trace flags are used to temporarily set specific server characteristics or to
switch off/on a particular behavior. There are two types of trace flags:
session and global. Session trace flags are active for a connection and are
visible only to that connection. Global trace flags are set at the server level
and are visible to every connection on the server. Some flags can only be
enabled as global, and some can be enabled at either global or session
(1) 260 (2) 1204 (3) 1211 (4) 1222 (5) 1224 (6) 2528 (7) 3205 (8) 3625 (9)
4616 (10) 7806 (11) 1400
To set on/off Traceflag:- (1) DBCC TRACEON (2) DBCC TRACEOFF
To Enable Trace flag globally :- DBCC TRACEON with the -1 argument
(Ex:- DBCC TRACEON 2528, -1)
-T startup option:- Indicates that an instance of SQL Server should be
started with a specified trace flag (trace#) in effect.
To Determine trace Flags are currently active:- DBCC TRACESTATUS
What are the common failures occur in SQL Server 2005?
There are three common failures occur in SQL Server 2005.
1) Database Failures
2) Physical Server Failures
3) SQL Server Service failures
What are the causes of Database Failures?
There are three common issues will causes Database failures. Log File viewer
is very useful to diagnose these problems that will occur in SQL Server 2005.
1) Database has run out of Disk space:a) If a Database is online, and running out of disk space the data cannot
be inserted into the database.
b) If the Database during recovery, and the data file becomes full the
Database engine marks the Database as Resource Pending.
2) T. Log is full:a) If the Database is Online, and the T.Log becomes full the Database
Engine issues 9002 error and it is in read-only state and will not allow
b) If the Database during recovery, and the T.Log becomes full the
Database engine marks the Database as Resource Pending.
3) TempDB has run out of Disk space:- TempDB stores User objects,
Internal Objects and Version stores. If the TempDB database runs out of
space, it causes significant problems for SQL Server 2005. The errors are
written to SQL Server log and these errors (1101, 1105, 3959, 3967,
3958, 3966) indicates TempDB has insufficient space.
How to understand Database Engine Errors?
If any error occurs, the server writes error messages to logs (Database mail,
SQL Agent, SQL Server & Windows NT). These logs having Error number,
Error message, Severity, State, Procedure name, Line number. We can easy
to understand errors by viewing Log file viewer.


What is Severity level in Event log? At what severity levels are
written to the SQL Server log?
The Severity level tells how bad the error is. Above 19 Severity level errors
are written to the SQL Server log.
What is State Attribute of an error message in Event log?
The state attributes provides details of what caused the error.
What are the Causes of Physical Server Failures?
There are five common issues will causes Physical Server failures.
1) Disk failures
2) Memory failures
3) Processor failures
4) Network card failures
5) RAID failures
If Log file is full what you will do?
If the T.Log file is full the Database issues 9002 error and it is in Read-only
state and will not allow updates.
The following tasks will responding T.Log file
1) Backing up the log
2) Adding one or more log files
3) Moving the Log to another disk
4) Increasing log file size or enabling auto growth
5) Teminating long-running transactins.
If Data file is full what you will do?
If the primary data file is full we can add secondary data files.
Adding a file to database: - Right click on database > Properties > Files >
click add > give the values for logical name, file type, file group, initial size,
auto growth, path and file name .

If a Database is under Suspect mode? What you will do?
sp_resetstatus:- Resets the status of a suspect database (sp_resetstatus
If the server has completely failed, and how to all the backups
restored onto a new server?
a) Build the Windows server and restore the domain logins to support
Windows authentication.
b) Install SQL Server and any service-pack upgrades.
c) Put SQL Server in single-user mode and restore the master database.
d) Restore the msdb database.
e) If the model database was modified, restore it.
f) Restore the user databases.
If a Server performance is slow? How you can troubles shoot a


If a Database Performance is slow? How can you do Performance
What are the Performance Issues? Explain them?
1) What are the Differences between Delete & Truncate?
Delete:- Delete command removes the rows in a table and records in
transaction log which makes it slow. Rollback is possible.
Truncate:- Truncate command removes all the rows in a table, but it wont
write log which makes it faster. Rollback is not possible.
2) What is an Index? Types of Indexes? How many clustered indexes
and non-clustered indexes created on a table?
Generally SQL Server examines (table scan) every row in the table to satisfy
the query results. Index is a physical structure containing pointers to the
data which is used for retrieving data more quickly and improves the query
Clustered Index:- Only one Clustered index can create on a Table. When we
create a clustered index on a table, all the rows in the table are stored in the
order of the clustered index key.
Non-clustered index:- 249 Non-Clustered indexes can create on a Table.
Non-clustered indexes are stored as B-Tree structures with the leaf level
nodes having the index key and its row locator.
3) How can we rebuild an Index?
4) What's the difference between a primary key and a unique key?
Both primary key and unique key enforces uniqueness of the column on
which they are defined.


Primary Key

Unique Key

Primary key creates a clustered Unique key creates a nonindex

clustered index
Primary Key doesnt allow Nulls Unique key allows one Null

5) What is Stored Procedure?

A stored procedure is a pre-compiled SQL statements that are stored in Sever
database to performing a task. A single procedure can be used over the
network by several clients using different input data. And when the
procedure is modified, all clients automatically get the new version.
Advantages:1) Stored procedure can reduce network traffic because queries executed as
a batch.


2) Improving the performance because the SPs are pre-compiled.

3) Stored procedures provide better security to your data
4) Easily modify the SPs when business rules change.
6) What is User Defined Function? Types of UDFs?
User-Defined Functions that allow you to define your own T-SQL functions
that can accept zero or more parameters and return a single scalar data
value or a table data type. There are three types of UDFs are available in SQL
Server 2005.
a) Scalar Valued UDFs:- A scalar-valued UDF accepts parameters and
returns a single scalar data types (Text, ntext, image).
b) Table Valued UDFs:- A table-valued UDF is a function that accepts
parameters and returns the results in the form of a table.
7) What are the differences between Stored Procedure and User
Defined Function?
User Defined Functions
Stored Procedures
1 Functions are compiled and
Stored procedures are
executed at run time.
stored in parsed and
compiled format in the

Functions cannot affect the state

of the database which means we
cannot perform
insert,delete,update and create
operations on the database.
Functions are basically used to
compute values. We passes some
parameters to functions as input
and then it performs some
operations on the parameter and
return output.
Function can not change server
environment and our operating
system environment.

Functions can not be invoked from

SQL Statements. Execute. SELECT

Functions can run an executable

file from SQL SELECT or an action

Stored Procedures can

affect the state of the
database by using insert,
delete, update and create
Stored procedures are
basically used to process
the task.

Stored procedures can

change server environment
and our operating system
operating system can be
invoked from SQL
Statements. Execute.
operating system use
Execute or Exec to run

8) What is a Trigger? What are the trigger models are available in SQL
Server 2005?


A trigger is a set of T-SQL Statements stored permanently in the Database

and automatically fired when an event occurs. They are used to impose user
defined restrictions or business rules and also provides high security on
Database/ tables.
There are two types of trigger models are available in SQL Server 2005
DML Triggers:- DML triggers created on DML statements like Insert, Update
and Delete of Database objects
DDL Triggers:- DDL triggers created on DDL statements like Create, Alter
and Drop of DB objects or DB.
9) Types of Triggers?
There are two types of triggers
After Triggers:- After Triggers will fires after the data is inserted into
the table. The typical use for an After trigger is to log the action to an
Audit or logging table
Before Triggers:- Before triggers will fire before the data is inserted
into the table.
Note:- DML triggers fires before or after issue, DDL triggers fires after the
What is a View and advantages of Views?
A view is a pre-defined SQL Statements that the DB engine executes and
retrieves dynamically. A standard view acts as a virtual table based on the
result set of a select statement. The fields in a view are fields from one or
more real tables or another views.
Advantages:1) To restrict the users to specific rows & columns and hide the columns with
sensitive data
2) User friendly names can be provided instead of base table column names
3) Frequently used complex Joins, Queries and Unions can be coded once as a
View and View can be referenced for simplicity and consistency of coding.
4) Aggregate information such as Sums, Counts, Avg and so on can be
calculated in a view to simplify coding when those aggregation information
will be referenced multiple times.
5) Views can be used for Data security, allowing users access certain data
without granted permissions to directly access the base tables.
Types of Views? Explain about Indexed View?
There are two types of Views 1) Standard View 2) Indexed Views.
An indexed View (materialized view) is like a standard view, and it has a
unique clustered index created on it. It stored physically just like a table.
Advantage:- Indexed views works best for queries that aggregates many
rows or have joins that cause response time of the standard view to be slow.

What is the difference between a Local and a Global temporary


Local temporary table:- It exists only for the duration of a connection or, if
defined inside a compound statement, for the duration of the compound
Global temporary table:- remains in the database permanently, but the
rows exist only within a given connection. When connection is closed, the
data in the global temporary table disappears. However, the table definition
remains with the database for access when database is opened next time.
A PRIMARY KEY constraint is a unique identifier for a row within a database
table. Every table should have a primary key constraint to uniquely identify
each row and only one primary key constraint can be created for each table.
The primary key constraints are used to enforce entity integrity.
What is UNIQUE KEY constraint?
A UNIQUE constraint enforces the uniqueness of the values in a set of
columns, so no duplicate values are entered. The unique key constraints are
used to enforce entity integrity as the primary key constraints.
A FOREIGN KEY constraint prevents any actions that would destroy links
between tables with the corresponding data values. A foreign key in one
table points to a primary key in another table. Foreign keys prevent actions
that would leave rows with foreign key values when there are no primary
keys with that value. The foreign key constraints are used to enforce
referential integrity.
What is CHECK Constraint?
A CHECK constraint is used to limit the values that can be placed in a
column. The check constraints are used to enforce domain integrity.
What is NOT NULL Constraint?
A NOT NULL constraint enforces that the column will not accept null values.
The not null constraints are used to enforce domain integrity, as the check