Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

MsSQL DBA Notes

SQL Server is a Microsoft RDBMS used for data storage, processing, and retrieval, with various versions and editions available. DBAs are responsible for managing SQL Server installations, backups, and high availability configurations. The document also outlines the environments in which SQL Server operates, the installation process, and the differences between data and information.

Uploaded by

pradeep serco
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

MsSQL DBA Notes

SQL Server is a Microsoft RDBMS used for data storage, processing, and retrieval, with various versions and editions available. DBAs are responsible for managing SQL Server installations, backups, and high availability configurations. The document also outlines the environments in which SQL Server operates, the installation process, and the differences between data and information.

Uploaded by

pradeep serco
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 147

1.What is Sql Server?

Ans. SQL Server is a Microsoft product. We can call it as Microsoft SQL Server or MS SQL Server.

Sql Server is a RDBMS (Relational database management system) software.

Before RDBMS, there is DBMS. Both DBMS and RDMS are useful to way of storing the data. But DBMS is working very
slow while retrieve the big data. So, the father of RDBMS is “EF. CORD” introduced RDMS. RDMS useful to create small
small tables and we can create relationship b/w the tables.

Sql Server is database software, which is used for storing, processing & retrieving the data.”

Every application needs a database in the backend.

Like SQL Server, we have other software’s also Oracle, DB2, MySQL etc.

In the market, based on the client budget, compatibility, requirement they will choose the database software.

Every application has 3 tier architectures as below,

Tier 1 – Front End

Tier 2 – Application

Tier 3 – Database (backend)

2. What are the duties & activities of DBA?

Ans. Installing and Maintaining the SQL Servers. Creating Logins & giving permissions.

Taking Backups & doing restores, database refresh tasks, backup failures.

Creating and scheduling jobs and maintenance plans.

Configuring high availabilities. Fixing and troubleshooting the issues. Tuning the Sql server.
3.What are the environments in organization?

Ans. There are two environments

1. Production (Live Application- it has the live data)


2. NON production (developers used to test new logic in the non-production application. It’s not a live
application. Used to test before applying to the production. Below are the non-production environments.
a. Dev
b. Stage
c. QA
d. UAT
e. TEST

Not all the companies invest on non-production servers.

For example, college Websites not getting any revenue. Only its useful to know the college information. So, for
colleges NON production environment is not required.

3. What is database refresh task or database refresh activity?

Ans. To test the any new logic in NON production, we don’t have any data to test. So, DBA will take the backup
from live application(production) and restore it in the NON production. Now, developer can test their logic in the
NON production.

4. In what environments you have worked in previous organization? (Interview question)

Ans. I have worked in production and non-production. In non-production, worked in Dev, Stage, QA, UAT & TEST.

5. What is configuring highly availability or HADR?

Ans. Used to keep the server highly available to the users or customers, even at the time of maintenance.

Below are the 5 HADR features helps to configure the highly availability of the server.

a. Log Shipping
b. Mirroring
c. Replication
d. Clustering (Windows server failure cluster (WSFS) and SQL server failure cluster (SSFS))
e. Always on

These features are called High availability disaster recovery (HADR).

These features help as secondary server to the databases and it helps when the primary server down,
immediately secondary server helps to work on the databases.

As a DBA, we have to configure, maintain & troubleshoot for all these HADR options.

6. Types of application?

Ans. a. External Application – used by the public.

b. Internal application – used by the organizations or banks or any institutions.

Whether internal or external application, will have a database

7. What is tuning the SQL server?

Ans. at the time of server response is very slow. We have to troubleshoot to improve the performance of SQL
Server.

Ex: User given the select query and taking lot of time to execute the command.
8. What is difference b/w Data & Information?

Ans. Data is a Raw formatted information. We can’t understand raw information clearly. By using database
software, we will convert the raw data in to information. Now, we can understand meaning clearly.

Raw data don’t have any meaning. Where, Information has a meaning.

When we add the attributes to the raw data it will be converted into information.

9. In which format data will be stored in the database software’s?

Ans. In the form of Rows and columns called it as Table. Tables are very easy to represent, process, understand
and retrieve the database. What is a table?
10. What are the versions of SQL Server software’s? (V.V.IMP interview Question)

Ans. SQL Server introduced in the year 1997. From SQL Server 2000 version onwards it’s become popular.

Below are the versions of SQL Server and release year with Compatibility. Each Version of the SQL server is valid
for 10 years only.

SQL Server Name Build Number Compatibility

Up to SQL server 2016, SQL Server is platform dependent only on Microsoft operating systems. It Means, SQL
Server will work only on Microsoft operating systems not in any other OS

There are 2 types of Microsoft OS,

a. Desktop OS (using for personal purpose like widows 7, windows XP, windows 10)
b. Server OS (Using in the organizations - windows server operating system)

In the organizations, we are not going to install Sql server in the personal laptops. We will be having virtual
machine or we have to create virtual machines on the organization, where we are going to install SQL Server on
the top of that we are going to instal windows server operating system. It means if you want to install a SQL server
in a virtual machine, we should install windows server OS first.

From SQL Server 2017 & 2019 are independent, can be installed in LINUX OS also.

If you want to install in any other OS, we have to install a virtual machine software like Oracle VM Virtual box,
create a virtual machine, install windows operating system and install SQL server.
11. What are the Windows Server Versions or server operating system versions?

Ans. In windows server operating systems also, From the Windows server 2000 version it becomes popular.

Windows server 2019 also came in to the market and it is the latest version.

In organizations Windows servers called as Boxes. Example: Please reboot the box.

The comfort Zone for installing SQL Server in the Server operating systems is -7 to +7.

For Example: If we want to install SQL Server 2000,

Then 2007-7=1998 and 2007+7=2012

So, SQL Server 2000 can be installed from any of the Windows server operating system, which was

invented b/w 1998 to 2012. It can be installed in the below windows servers.

12. what is Build number?

Ans. Build number helps to find out the version of the SQL Server.
We can find the build number in the SSMS (SQL Server management studio), Below highlighted is the Build number
and match that with the above SQL Server Versions. Below is the 2019 version.

Build number contains four parts, majorversion. minorversion.Buildnumber.revisionhistory(15.0.2000.5).

Here 15 is the major version,0 is the minor version,2000 is the build number and 5 is the revision history.

By using query, we can find out the build number with version together,

Query: Select @@ Version; and it represents like below

13. What is CTP, RC, RTM & SERVICE PACK?

Ans. CTP – Community technology Preview. It is also a SQL Server software, which is used for testing purpose. any
new software is ready, first Microsoft release the software to the community people to test the software. It’s a
test phase. Here users will work on the software and give the feedback to the Microsoft. Now Microsoft will rectify
the bugs and errors.

RC – Release Candidate. It is also a SQL Server software. Once CTP Completed, Microsoft will release one
more test copy to Release candidate. Here also users will work on the software and give the feedback to the
Microsoft. Now Microsoft will rectify the bugs and errors.

RTM – Released to market. After completing the tests in the CTP and RC. Microsoft release the software to
the market. This is the base version or first copy of software is called RTM Software.

EX: Client is asking to install SQL Server 2016 RTM. It means we have to install first copy of SQL Server 2016.

SP – Service Pack – It contains the updates of the RTM Server. If we want to install any updated, we use
service packs.

CTP and RC software are free versions, which can be installed by anyone in the desktop OS.

RTM is the paid version, which can be installed in server OS.


14. What are the editions in the SQL Server?

Ans. Limitations to the features of the software is called Edition.

Below are the famous editions from Microsoft SQL Server,

a. Express Edition- It’s a free edition. This edition won’t allow to create a database more than 10GB. There is no
SQL Server Agent in this version.
b. Evaluation Edition- it is also a free edition but for limited time period that is 180 days only. In this edition also,
so many features locked to access.
c. Standard Edition – it’s not a free edition. This will be used in the Production environment. Not all features
unlocked.
d. Developer Edition – From SQL Server 2017 Version onwards, It’s a free edition. This edition can’t be installed in
production environment.
e. Enterprise Edition- This is the highest edition. It’s not a free edition. This will be used by the Production
environment. All features unlocked in this edition.

95% of the organizations are using Enterprise edition only.

Paid Editions are Standard and Enterprise

Free editions are Express, Evaluation & Developer Edition.

15.What are the main components or features or applications or ADD ONs in the SQL Server?

Ans. Below are the main features of the SQL Server.

a. Database engine Services- This is the brain and heart of the SQL Server. SQL Server is running based on the
Database engine services.
b. Business intelligence development studio (BIDS)
c. Reporting Services – To generate reports
d. Analysis Services
e. Integration Services – To import data into SQL Server from external applications

When the client is requested to install the BIDS or Analysis, Integration services then only we have to install these
features in the SQL Server. Why because these are the ADD ON, Client has pay extra money to access these features.

Before installing any SQL Server, we have to ask the client- Please provide the build sheet. In the build sheet, they will
mention everything like Which version of SQL Server, Windows Server OS, RAM, Storage, ADDONs etc.

15. What are the types of machines?

Ans. There are two types.

a. Physical Machine – We can touch the machine


b. Virtual Machine – We can’t touch the machine but we can feel it.

In a single physical machine, we can create number of virtual machines based on the capacity (RAM, Storage)
of the physical machine. If physical machine is down, we can’t access the virtual machine.
Every physical Machine have three important components to install the any application those are OS, RAM,
Hard disk, CPU.
In the same way to create the virtual machine in the physical machine, below are the few software to create
the virtual machine. These softwares are called Virtualization Softwares.
a. Oracle Virtual Box
b. VM Ware
c. Hyper V (It’s a Microsoft product) etc
16. How many physical and virtual machines is there in your previous organization? (Interview Question)

Ans. 80-90 % are virtual machines and 10-15% are Physical machines

17. What is the process in the organization to install SQL Server or any software? (Interview Question).

Ans. 1. we have to Raise the Change request or Ticketing for installing SQL Server.

2. VM Team creates the Virtual machine

3. Windows team will install the Windows server OS

4. Network team will install network drives

5. Now it comes to DBA team to install SQL Server.

DBA performance can be track with all the Change requested and incident requests in the organization.

Note: Never shutdown the any server because server should run 24/7. If you have any problem restart the
server. If your work is completed logoff from the server. DBA never shutdowns the server.

To log off from the server, open Run and type Log off.

If there is any pending work in the server like backup, restore, query handling, jobs running etc, don’t log off
from the server. Just click on the “X” button of the server, now your session only will disconnect and pending
work will be continued in the server.

18. How to connect to the server remotely?

Ans. In the organization, we will already be having the IP address or server name to login to server.

a. Open the Remote desktop option by typing in the search button “remote” or “RDP” or type “mstsc” in the
RUN on your laptop
b. Type the IP address of the Virtual Machine in the above Remote desktop connection and connect.
c. After that give the user name and password to login server.
d. Now you can access the virtual machine on your laptop.

e. Now login to the server by using the User name and password. User name is always administrator
f. Windows server allow only 1 admin and 2 users to access the server at a time. If you want to access the same
server, then you to kill the 1 user access. But before killing the user access ask them and then do it. Without
their permission don’t kill the any user access.” Ask the user, I want to connect to the server, please
disconnect your connection from the server”.
g. If you’re working from home, to connect to the organization virtual machines use the VPN

`
19. How to install SQL Server or Instance?

Ans. One instance is called One SQL Server software. We can install 50 standalone instances in a single Windows
Server. Below are the steps to install SQL Server. (Interview Question). Prerequisites will be installed by windows
team or application team. If any perquisite is missing, we should ask them to install.

a. First copy the SQL


Server setup from
the Shared paths to
the virtual
machine.
b. Open the Setup
folder and run the
setup file as
administrator.

c. Now SQL Server installation centre will be opened like below and go to installation page.

d. If you’re installing the SQL Server in the single windows server or single machine it’s called stand-alone
installation.
e. Click on the new SQL server
stand-alone installation for
installing a fresh SQL Server or
to add any additional features
to the existing SQL Server Like
Reporting services,
Integration services etc. after
that below screen appears.

f. Select the edition type. In the organization’s product keys available. Click Next. After that accept the
license acceptance click next

g. Now the page goes to check,


whether prerequisites of SQL Server
installation. If any check is failed,
Next Option won’t work in the setup.
we have to install that software first
and then we have to continue the
SQL Server setup.
h. Now Microsoft update screen
will come. In the
organizations, Servers won’t
have internet connections.
So, don’t tick the Microsoft
update option and click next.

i. Now, it will install setup files.


After it will do the checks like
below, if there is any check
failed, installation won’t
continue.

j. Install Rules and Selecting


Components or Features.
Instance Features or services -
These features, we have to
select for each and every
instance or Sql server.
Select database engine services,
SQL Server replication & Full-
Text semantic Extraction. If any
other services required by
client, then only select the
other features. These features
are also called as specific
features or instance aware
services
Shared features or services-
Selected features in this
column will be applied to all
the SQL Servers. It means,
when you want install
second instance, shared
instances have been
selected already. Only any
other features are required
we have selected in this
column again these features
will be applied to all the SQL
Servers or instances. These
features are also called as
instance unaware services.
Select
Client tools connectivity
Client tools backwards
compatibility
Client tools sdk
Sql client connectivity SDK

If you go to services.msc, the shared services will be used for all the SQL Servers in a single virtual machine. But, in the
specific services- separate copy of services will be created for each SQL Server in a virtual machine. To identify, which
services of SQL Services in services .msc is Specific or shared- At the end of the service instance name is there means
it’s a specific service otherwise shared service.

For example: if you already installed the first instance in the windows server with 3 specific services and 2 shared
services of sql server, then for the second instance only specific services only created and already created shared
services will be used for the first and second instance. Now total 6 specific and 2 shared will be running in the
services.msc of SQL Server.

k. Up to SQL Server 2016, Reporting services are available in the feature selection. After that onwards, this
feature has been separated and we have installed separately this feature when there is a client
requirement.
l. Instance Configuration.

There are 2 types of instances.

Both will act as same only the difference is the way of connecting to the server is different. We can
choose any one.
 Default Instance – To connect to the default instance, Will use “Computer name” to login the
server. Only one default instance can be created for one Windows server. By default, it takes
the computer name as Instance name. No need to give any name of the instance
 Named Instance - To connect to the Named instance, will use” Computer name\Instance
name” together. Named instance will allow maximum of 16 characters for the name. Instance
name should start with alphabet only.
Special characters not allowed in the named instance name, it allows only “_” and “$” only.

Instance ID – it will create the folder for


the instances with the name whatever
we mentioned.

*) we can see already installed instances


also in this screen

m. Service Accounts –

Any machine has 3


service accounts.

Below services will do


the work for the all the
softwares, based on
their selected service
accounts.

 Local service
 Local System –
Very IMP
software runs
under the Local
System. Read,
write operations
happened in this
account.
 Network
Service

By default, windows give a service


account for SQL server. We can use
the same or else we can select the
Local system as Sql server service
account or we can create
customized services accounts for
the Sql server. Start-up type for SQL
Server agent & Sql server database
engine change to automatic.

In the same screen, Collation tab is


there- Collation means language
setup for the SQL databases. By
default, “SQL Latin 1” will be there-
It’s an English language. We can
change it as per client requirement.

n. Database engine Configuration.

There are 2 authenticate modes in the SQL Server.

 Windows mode- By using the windows user


 Mixed mode – by using windows user or SQL Server user login details.

We have to add the list of the


users we want give access to
the SQL Server by using add
current user and add option
for other users. We can add
the others users after the
installion also. But at least to
login after the installation of
Sql server, we should add the
current user. If we won’t add
any users at this step, we
can’t access the Sql server
after the installation.
Normally in the organization,
we will add the all-DBA users,
Customized Service accounts
at this option.

Next go to data directories and give the location to store the data directories.

Next go to TempDB and configure the database


Next go to File stream, if you want to store movie content enable it.

o. Finally, Ready to install -All the


above GUI options stored in a
“configurationfile.ini” file used
for the installation.
GUI is only to understand the
process to the user. Everything
inside the application
happening in command form
only.

20. What are the regular activities of DBA?

Ans.

 Installing SQL Server


 Configuring SQL Server
 Taking backups
 Restore backups
 Troubleshooting the backup & restore failures
 Drive space monitoring
 Jobs
 Patching
 Sql Server upgradation or migration
 User Deployments
 HADR Options (Log Shipping, Mirroring, Replication, clustering, always on)
 Performance tuning of the server

21. How to install Sql Server management studio (SSMS)?

Ans. From SQL Server 2016 onwards, Microsoft separated SSMS feature in the SQL Server software.

We have to install SSMS Separately from the SQL Server 2016. SSMS is tool to connect to SQL Server.

We can connect lower version sql server instances in higher version management studio.

We can connect higher version sql server instances in lower version management studio. But We won’t get higher
version features of SSMS

Copy the SSME Software from the Shared folders to the Windows server and then install it. Don’t install from the
shared folder directly. It’s not a good habit. Always copy any software to the virtual machine first and then start
the installation. Open the installation file with Run as administrator.

No need to install separate SSMS for all the instances. With one ssms we can connect to all the sql servers.

Click on install.
22. What are the ways to connect SQL Server by using default instance?

Ans. There are 5 options.

 By giving “ .” (dot) in server name

 BY giving “Computer name” in the server name

 giving “localhost” in the server name.

 by giving “(local)” in the brackets in server name

 By giving “IP address and Port ID” in the server name

Remember default Port ID for default instance is


1433. (Interview question) or you can see the port id
in the sql server configuration manager.
Below is the example where default instance connected with four different ways.

23. What is Parser?

Ans. It helps to identify the Syntax & Symantec errors. Short cut is Cntrl+F5.

24. How to select the database while running the query itself.

Ans. Syntax: select * from Table name databasename. schema. tablename

Example: select * from employee Testdb.dbo.employee

25 Which database is hidden in the System databases?

Ans. Resource Database.


25. What are the ways to stop & start SQL Server or instance?

Ans. There are different ways.

 Open services.msc, select the sql server instance and stop it


 Open sql server configuration manager, select the instance and stop it
 Open the command prompt, type “net stop instance name”

We can start the instance from the above options, from command prompt type “net start instance name”

26. Physical hierarchy or architecture of physical server?

Ans.

 Data base is a collection of data files and log file.


 Data files created under the file groups. By default, data files created under primary group.
 In the organization, datafiles stores in separate drive, log files stored in separate drive & Temp DB in separate
drive.
 Organizations maintains separate drives for backups.
 Separate purpose, there is separate drive in the organization.
27. Logical hierarchy of SQL Server?

Ans.

 Schema- A collection of tables. It’s a container.

28. What are the files in a database?

Ans. Datafile and log file.

Data file Extension is mdf and log


file extension is ldf

Note: While creating any object in


the database, change the owner name
“default” to “sa “.

We can change the owner of the


already created data bases also, by rgt
click in database – open properties-go
to files option – change the owner to
sa

 Give the path for storing the data


file and log file.
29. How to know all the databases names, owners , size of the database?

Ans. Query is SP_HELPDB and executes like below

30. What are the system databases?

Ans. When we install SQL Server, we will get 5 system data bases. Only for sql server 2000, we will get 4 system
databases. Without the system data bases, Sql server won’t work. To start the sql server, there should be 3 files,
Master data file, master log file & error file. These 3 files are called start up parameters. We can see the start-up
parameters in the Sql server configuration, right click on main server and go to start-up parameters option. Here
we can see the path of start-up parameters of sql server.

Below are the System data bases

1 Master: This is the main database, which controls the sql server. The meta data of each object will be
stored in the master data base. META data base means, data about the data (It means how many
columns, rows, storage, path, logins, size etc of all the objects). To create any objects like database,
logins, tables, records etc created by the master only. It stores the information of the other system
databases and user databases. We can’t start sql server, if master data file & log file corrupted.
Always master data first comes online in the sql server, because of it contains all the paths of the
other databases. Instance level configurations also stored in master data base only.

2 Model: Model database will act as a template for newly created databases. All the new databases will
follow the default settings of the model database to create the database. Even model database is
corrupted, we can’t start SQL Server.
3 MSDB: All the automation information (like job, backups, restore, maintenance activities information)
will be stored in this data base. If MSDB is corrupted, SQL server can start but automation of jobs or
maintenance activities will stop. It’s an optional to start the SQL Server.SSIS packages information
stored in the MSDB.
4 TEMPDB: All the users will store the data in TEMP DB for temporary. It’s better to maintain a separate
drive for TEMP db. We can’t take backup of TEMP DB , because whenever we restart the server new
TEMP DB will be created. If temp db is corrupted, sql server will be down. Index rebuild and sorting of
data will be done in TempDB. It acts as a RAM to the SQL Server. We can’t start the sql server if there
is no TempDB. New temp db also depends on the template of model database. That’s why without
model database we can’t create temp db, so without TempDB we can’t run sql server. So, both model
and TempDB also required to start the sql server.
5 Resource: It’s a hidden data base. Not visible in the SSMS. In this database, all the objects stored
physically. Whatever data stored in the master; the same data will be stored in resource db also but
only in the physically. In master data stored in logically. Before SQL Server 2005, there is no resource
data base. In SQL Server 2005, we can find the resource db in data folder of SQL instance. From SQL
Server 2008 onwards, it’s a hidden data base. We can find this data base in root directory \binn folder.
31. Where to check the error, if the Sql Server not started?

Ans. Open the RUN and type “Eventvwr” (Event Viewer). - Its stores all the applications errors.

Go to Windows logs option, and select the application, where you can see the error details.
32. What is the order of system data bases when we start the SQL Server?

Ans.

a. Master
b. Resource
c. Model
d. TempDB
e. Msdb
f. User data bases

33. What are the data base id for the System data bases?

Ans.

34. What is the query to see all the data files and log files?

Ans. select * from sys. sysaltfiles

35. What are the types of data files?

Ans. There are 2 types.

a. Master data file(mdf) – It stores the meta data of each data base. Already discussed in the above
pages. Default file group is primary.
b. New\next data file(ndf) – if you want store the data file in .NDF, then create a new file group.

36. How many databases or logins or users or files or file groups etc we can create?

Ans. 32767
37. What are pages?

Ans. Pages is nothing but the basic storage unit of data file. All the data files of the SQL Server stored in pages only.

Each page is 8 KB. We can’t change the page size. Its fixed. A page is used for only for one object. Each object will
have separate pages. But single table can be stored in multiple pages.

Suppose we have a database size of 1 GB = 1024MB=1048576 kb= 1048576/8=131072 pages are size of this
database. A page contains 3 parts,

a. Page header – its stores the meta data like Page id’s, object Id’s,
how much space in this page etc.
b. Body (Actual data) – Data or records will be stored in row-by-row
manner.
c. Row offset – Its works as index. It’s had the address of each data
or record

Page header use 96 bytes of space,

Row off sets use 36 bytes of space,

Balance size of 8060 bytes used for body. Total 8192 bytes=8 kb = 1 page

1MB – 128 pages

38. What are Extents?

Ans. Extent is a collection of 8 pages. It’s a basic allocation unit of sql server data file.

1 page = 8kb=8*8=64 kb = 1 extent. So, size of each extent is 64 Kb. It’s a fixed size we can’t change.

We have two types extents,

A. Mixed Extent – all the 8 pages can be used for multiple objects
B. Uniform Extent – all the 8 pages can be used for only single object.

For example, whenever we create table, sql server first create the one mixed extent with 1 page to save the
storage. When the data is increasing in the data file, then all the subsequent pages of same datafile will converted
in to unfirm extent.

Remember, while created the object- sql server choose the mixed extents only.

Depends on the data, SQL Server will allocate Mixed extents and uniform extents to the data file. Mostly it
allocates mixed extent.
39. What are the types of pages?

Ans. Mainly we have 2 pages,

1. Data pages - 3 types

All the data will be stores in the any of the below 3 types pages only.

a. Data page – it will store the small data types data except large data types like text, ntext, image,
nvarchar(max), varchar(max), varbinary(max) and xml data.
b. Index page – it stores the indexes.
c. Text/image it will store the large data type data like text, ntext, image, nvarchar(max), varchar(max),
varbinary(max) and xml data.
2. System pages - 6 types
a. Gam/SGAM (Global allocation map\Shared global allocation map)-

GAM: It tracks the status of extents, which extent is free and which extent is allocated. It tracks the
status in zeros and ones.

Bit 1 = Free extent


Bit 0 = allocated extent
SGAM: It tracks all the mixed extents, which is having at least one unused page or space. If the bit is 1
then extent is used as mixed extent with free page.
b. PFS (Page free space): it will record the information about page allocation and free space available on
pages. It will calculate in percentages.
c. IAM (Index allocation map): it will track information about extents used by a table or index per
allocation unit. It will track all the tables and in which extent table is present.
d. BCM (Bulk changed map): information about all the extents, which are modified by the bulk
operations. Like bulk insert, bulk updates etc. So, when we did the bulk operations like inserting, data
will be stored in any pages and extents will be changed. These modified extents will be tracked by
BCM.
e. DCM (Differential Changed map): information about extents that have changed since the last full
backup database statement per allocation using all the changes that we can do to an extent.

To see on what pages data is stores, use the


query,

DONE USE ALL THE BELOW QUERIES IN


PRODUCTION

(DBCC- DATABASE CONSOLE COMMANDS)

“DBCC IND (DB NAME, TABLE NAME, -1)”

-1 is used for display option

To see the page internals,

First this query “dbcc traceon (3604)”

Second query “Dbcc page (db name, file id, page


id,1)” (1 IS TO DISPLAY)
40. What are the types of transactions in SQL Server?

Ans. A query is called a transaction.

There are 2 types

a. Implicit Transaction: All the implicit transactions are auto committed. It means without Begin Tran and
Commit

EX: insert in to table values(1,”name”);

b. Explicit Transaction: All the explicit transactions are not auto committed. We have to mention commit.
If we won’t mention commit, data will be stored temporarily only.

Ex: begin Tran

insert in to table values(1,”name”)

Commit

41. Explain Log File architecture?

Ans. log file stores the transactions.log file


contains virtual log files (VLF).

There are 2 types of log files in architecture,

a) Active VLF: Currently which is holding


the transaction is called Active VLF.
Active VLF contains Log blocks.
Each log block contains Log file/Record.
One record is one transaction.

b) Inactive VLF: Log file, which doesn’t


contain any transactions is called
inactive VLF.

To see how many VLF’s is there for each data


base log file

Use the query “dbcc loginfo”


42. How to shrink the log file or how to release the unused space of the log file?

Ans.

a) right click on database, select the tasks, choose the shrink option, select files like below

b) Choose the file type as log, and here


we can see, how much space
allocated to log file and how much is
free space available.
a. Here we have 2 actions, one
is releasing unused space,
two is reorganise pages
before releasing unused
space.

Choose the 2 nd option to shrink the log file


size. Like screenshot provided.

In the organizations, we won’t do the


shrinking for 1 gb or 2 gb. We do for bigger
sizes.

43. To Which system data bases, we can create a new file groups and data files?

Ans. Only MSDB allows to create new file group and files.
44. What is service packs?

Ans. Service packs are major updates of the SQL Server. Within a year or 2 years once, Microsoft release the
service packs. Once service pack released, Microsoft send the emails to all the customers. After that, service pack
update will be download by managers or team leaders from Microsoft website and kept in the shared folder. Now,
DBA will patch the service packs to sql server. We can install any service pack, it’s not mandatory to install in
order. We can install the latest one sp4 alone. Whenever we uninstall any service pack, SQL server will go to the
previous update of service pack sp1 or sp2 or sp3. If there are no previous service pack updates, SQL Server will go
starting level RTM Copy (Release to market.)

Microsoft
release up to
four service
packs only.

From SQL Server 2017 version on wards there is no Service packs.

45. What are cumulative updates?

Ans. Cumulative updates are minor updates of RTM or service packs. Within a month or every 2 months, Microsoft
release the cumulative updates. In cumulative updated, there are 2 types,

These are called hot fixes.

a. GDR (General distribution release): it’s a security update to safeguard from the viruses, threats.
b. QFE (Quick fix engineering): This update helps to fix the bugs.

On RTM Copy also Cumulative updates will be there. All the


service packs also will have Cumulative updates. If you want to
install any cumulative update of service packs, you must patch the
service pack first and then you can patch cumulative update.

From SQL Server 2017 version on wards there is no Service


packs.

46. What are the precautions before patching the service packs or CU to SQL Server or production server?

Ans. Patching is a downtime activity. Whenever we want to patch, we have to restart windows server first. We
should not restart the windows server directly; we have to take proper approval. Patching will take 45 mins to 1
hour time. During the patching, SQL Server restarts multiple times automatically. That’s why, we can’t patch the
sql server during business hours. Below are the precautions before patching.
a. First find the application owner.
b. Inform to owner about downtime and ask for the timings to do the patching.
c. Timings, which are provided by the owner is called “patching Window”.
d. Raise a change request with start time and end time of patching.
e. CAB (Change authority board) will discuss about the request
f. CAB will approve the change request.
g. Now DBA start the patching as per Patch window

47. What are the precautions we have to take when you are going to start patching & after finishing patching?

Ans.

a. Check how many SQL Servers or Instances are running in the same Windows Server. Because when
you start the patching windows server needs to restart. At this time, other instances also go off line.
b. Take the screenshot of SQL Server Configuration manager before starting the patching. Because some
of the servers are already offline and some servers are online. We don’t know which server in online
or which server is offline after patching. So, to keep the servers in the same online or offline position
keep the screen shot of configuration manager with you.
c. Take the screen shot of database status before patching. Few databases already in offline or restoring
mode like that. After patching, screenshot helps to check the databases are in the same status or not.
d. Make sure the name of the server in the object explorer should match with running the query
” select @@servername”. If both are not matching, patching will be failed.
e. Check the build numbers before patching in the object explorer and Query “select @@version”. Both
should be same.
f. Make sure you have a proper free space in the drive at least 3 GB. If you have less space, ask the
windows team to extend the space.
g. request the windows team to take the Virtual machine snapshot (it means back up of entire virtual
machine) – it helps if SQL Server not starting after patch-up. Windows team can restore the entire
virtual machine.
h. Check whether machine is physical machine or virtual machine. (We can check it, by typing “system
information” in the windows search box, there you can see system model tells us it’s a VirtualBox or
vm ware or hyper wiser etc for virtual machines. If it’s a physical machine, system model tells us HP or
Lenovo or dell or ASUS etc). if it’s a physical machine, try to patch on week days instead of weekends.
Why because, if after patching physical machine is not coming online- in week days no one will be
there in office to turn the physical machine online.
i. Send an email to whole DBA Team.
j. After all the above precautions start the patching process.

48. What is the query to know the server name & Version of the sql server?

Ans. select @@servername – for server name

Select @@ Version – for version

49. What are steps to install Service Pack or Cumulative update?

Ans. After installed the cumulative update or service pack how will
know whether patching done successfully. After update, the build
no. of the sql number will change. There will come to know patched
successfully.

a. Copy the service pack or CU from shared path to the


windows server. (Which is already downloaded and
kept in the shared folder by team leader or project
managers)
b. Right click – run as administrator
c. Accept the license terms, click next

d. Select the which server or which instance, you want to patch, click next

e. Now it will check files in use. Like below, click next


f. Ready to update screen will come like below, click next.

g. Update completed screen and make sure all the features in this screen succeeded. If any feature is
failed, Patching is failed.

h. Now check the versions of build no’s

Before patching version screenshot After patching version below

i. Now follow the precautions after installation discussed in the before pages.
50. How to Remove patches of SQL Server?

Ans. Organization very rarely ask to remove the patches, when patches are not installed successfully like the
object explorer build no. and @@Version build no. are not same. At this time, we have to remove the patch again
we have to reinstall the patch. One more case also is there like, Applications are not compatible with the latest
service packs or CU, then also we have to remove patches.

For compatibility issues, one way we can ask the application team to upgrade the application or else We have to
remove the patch.

When we remove the CU, SQL Server goes to previous installed CU. If there is no install CU installation happened
previous, then it will to RTM.

To remove patches also need a change request, why because this is also a downtime activity.

Steps to remove Patch:

a. Type Run command “appwiz.cpl” or open control panel and select add or remove programs. Here we can see
all the installed applications.

b. Click on view installed updates, where we can see all the service packs installation and CU installations.
There will be components updates and main sql server update also. We have to remove main sql server
update, then automatically components update also removed.

c. Select the Main sql server update and click on uninstall. Now
uninstall process starts.
d. After that, uninstall window will go to features tab, where we have to select, which sql server instance update
you want remove. After that click next.

e. After that, Click remove.

f. Some times while doing the uninstalling, Sql server


will asks for Main RTM Software CD like below. Give
the address where the RTM Copy installation setup is
there and click ok.

If the same error is kept on coming after given the path of


RTM Copy, Then Microsoft introduced one tool called

“Fix msi missing tool”. Download it and install in the


windows server.
g. Uninstall complete.

51. What are the terminologies used in organizations for different types of teams?

Ans. Windows team are called WIN OPS (Windows operators)

Virtual server team are called V OPS (Virtual Operators)

DBA Team are called DB OPS (Data base operators)

Network Operators are called NET Ops (Network Operators)

52. What are the terminologies in the SQL Server security?

Ans. Mainly we have 4 terminologies,

a. Authorization: having access on objects or databases is called authorization.


b. Authentication: The process of verifying the authorization is called authentication. For example: giving
username and password to enter a database, after that authentication process starts on verifying the
login, whether this login is there or not in the database. If it’s there, then user can login otherwise
can’t.
c. Principle: Those who are accessing the resources or database is called principle.
d. Securable: What resource you are accessing, those resources are called securable.
53. What are the authentication types of SQL Server?

Ans. There are 2 types,

a. Windows authentication: This mode not required any username and password.it reads the user name
from windows and login in to sql server.
b. Mixed mode or SQL server authentication: This mode required username and password for the users,
which are created by the DBA.
54. What is the difference between login and user?

Ans. To access the SQL Server, Logins are created. Once login created, to access the database dba will give
permissions, now a user will be created in the database. By simply creating login, user can’t enter in to any
database. A user will be created in the database, then only login can access to that particular database.

Instance level access is a login

Database level access is a user

55. How to create a SQL Server login via windows authentication mode?

Ans. There is prerequisite before creating a windows login, that is user name should be there in the windows level
or in the active directory level. In the organization, users will be created in the active directory level.

Creating windows level user:(This is not DBA job. Windows people will create the windows level user)
a) First login in to windows server.
b) Type run command “lusrmgr.msc” (Local user manager)

c) Right click on the user, select new user, Fill


the columns username, password etc. Click
create.
d) Now user got created

Windows user level account has been created. Now we have to add the user in the sql server via Windows
mode Authentication.

A. Open SQL server, Expand Security tab, Right click on logins, select new login.

B. Select the Login type as windows authentication and click on the search button beside to the login
name.

C. Give the created windows lever user


name in the box, click check names. Now
it will check for the username. Once it
founds the windows level user, SQL
Server will add the user. Click Ok.
D. No need to give any password here, because while creating windows level user. We can give the
password. The same will be used by SQL Server.
E. Click ok. Login created. Now we can see that user name in SQL Server.

F. Now user can access Sql server. But not able to access any Databases.

56. How to create a SQL Server login via windows authentication mode or SQL Server authentication mode?

Ans. There is no prerequisite to create a SQL Login via Mixed Mode.

a. Open SQL Server, expand security, Right click on Logins, Select New user.
b. Select SQL Server authentication, Give the login name, give the password, Click ok

c. Login successfully created.


d. Check the properties of SQL Server and keep the security type of server authentication mode to Mixed
mode. Otherwise Sql Mode logins not able to enter SQL Server, we will get error.

e. After changing the server authentication mode, it will ask to restart the server. Restarting the SQL
Server is down time activity. While installing the SQL Server it self , We have to select Mixed mode . So
in future, This kind of restart issues wont come while creating the logins.
f. After restarting the SQL Server, now login to the SQL Server with the SQL user name and password.
Like below.

57. How many users or logins or databases anything we can create in a single SQL Server.

Ans. 32767

58. What is a group login?

Ans. When a group from same team have the same permissions to access the database, that time we can create a
group login. Instead of creating individual login for all the team members, we can simply create single group login
and give access to a team. Even in future any new user joined to the team, we can simply add the user name in
that existed group login. Now new user can access the database. All the organizations prefer mostly group logins
instead of individual logins. All the users part of a group login has the same permissions.

Group logins, we can create only for the windows authentication mode. In SQL Server authentication mode, Group
logins not possible to create.

Prerequisites to create the group login is windows level logins or Active directory user logins

These windows level logins or Active directory user logins will be created by windows team not the dba.

Once the group users created by Windows


team, then we have to create group login in
sql server.

How to create a Windows group login: (it’s


not dba job)

a. Open run type “lusrmgr.msc” and enter


b. Create the list of users, by right clicking
on users option and select new.
c. Give the username and password
C. After created the list of users, you can see like below.

D. Right click on Groups folder and select the new group. Enter the Group name and add the users to that
group. Click ok.

d. You can see that group name in the list, like below.

e. We can add the users to the group, if any new users joined in the same team.

Creating group login in the SQL Server: (This is a DBA job)

A) Open SQL Server,


Expand Security, Right
click on logins, Create
new.
B) Select Windows authentication mode only for Group logins.
C) Click on search button, click the object type and tick the object type Groups like below. Click ok.

D) Type the group data base name and click on check names. Click Ok.

E) Click ok. Group login created. By seeing the icons of the logins, We can findout, Which is individual login and
Group login. All windows authentication logins starts with computername only, whether it’s a individual or
group.Any login with out computer name those are sql server logins.
F) If any new user joined in the same team, DBA no need to do anything. Windows team create the Windows
user and they will add in the SQL DBA group. Now new user can access the SQL Server.

59. What is the query to see all the logins list in the SQL Server?

Ans. “xp_logininfo”

60. What is the query to see the list of users in group login?

Ans. “xp_logininfo groupname , members”

61. What are server roles?

Ans. There are 2 types of server roles.

a. Server – level – roles – It helps to manage the permission on server level(8+1 roles)
b. Database – level – roles – it helps to manage the permissions in database level(9+1 roles)
62. What are server level roles?

Ans. Collection of permissions is called a role. Each role has a set of


permissions. Based on the user requirements will allow the users to
access the particular roles. These roles are fixed and we can’t modify
the permissions of the roles. To remember the below roles code
BD2PS4

There are 8 + 1 roles in the server level, 8 roles are fixed and 1 role is
not fixed. PUBLIC & SVS admin are not fixed roles.

1. Bulkadmin :
2. Dbcreator :
3. Diskadmin :
4. Processadmin :
5. Public :
6. Security admin :
7. Serveradmin :
8. Setupadmin :
9. Sysadmin :

“Add member “ permission in the all the server roles has the same kind of activity , if you have access to that
server role, you can add other users also to that role.

To know permissions of each server When we want a particular server role permission,

role use the below query use the below query

“SP_SRVROLEPERMISSION” OR “SP_SRVROLEPERMISSION BULKADMIN”


1. Bulk admin : Bulk admin server role has 2
permissions.
a. Add member to bulk admin:

If you are member in bulk admin, you can add


another user to the bulk admin.

b. Bulk insert
2. Data creator:
Bulk admin have 8 permissions.
A member of db creator can do all the below
activities.
a. ADD member to Dbcreator
b. Alter database
c. Create database
d. Drop database
e. Extend database
f. Restore database
g. Restore Log
h. SP_renamedb

3. Diskadmin:

99% we won’t this disk admin roles.

4. Process admin : A member of process admin can kill


the sessions.

Below Q .no 53 explained about sessions and how to view


sessions.
5. Public :

It is not a known fixed role. By default , each user got


the public server role. This role doesn’t have any
permissions. We can’t remove this role to any user. while
creating the login itself , login created with default
member.

6. Security admin: A member of security admin has 16


permissions.Security admin can create logins, drop logins,
changing the passwords of existing logins etc.Security
admin can see all the logins in the security tab.
They can also GRANT, DENY, and REVOKE
database-level permissions

7. server admin: A member of server admin can shut


down the SQL Server. Server admin can configure the
sql server like changing the settings.

8. Setupadmin:
Members of the Setupadmin can add and remove
linked servers. By using the linked servers, we can
create link between the other RDMS Software to the
Sql Server. Like we can connect from sql Server to
Oracle.
9. SyS admin: Sys admin have all the roles. A member of sys admin
can do anything. If a user is member of sysadmin, he/she got all
the server role permissions. SYS admin can access any
permission, even there is deny.

63. What is GRANT, WITH GRANT, DENY?

Ans. GRANT : Which is used to give permissions to a user

WITH GRANT : which is used to give permission to user and the user also can give permissions to other users.

DENY : Not giving permission to access the database. Once the deny applied to any user, he/she can’t access the
database till the DBA removed the DENY

Deny is the highest privileged permission. For a particular database, a user got grant and deny permission. Deny
only will work. GRANT option won’t work. Except sysadmin. Sysadmin can access even there is deny.

Sysadmin is the first privileged user & deny is the second privileged user in the server level roles.

Deny is highest privileged user in the data base level roles.

64. What is the query to see what are the


processes running currently in the sql server?

Ans. “SP_WHO2” OR “SELECT * FROM


SYS.SYSPROCESSES”

Any work done in the sql server in a session only.

It helps to find out who is using what database and


to find out how many users currently using the sql
server.

 1 to 50 sessions are back ground sessions.


 From 51 session onwards, user sessions will
start.
We can’t kill any of the back ground sessions. We can kill only user sessions. To kill the session, user should be
member of Process admin. This killing sessions processes used for Performance tuning. In the organizations, user
asks the DBA to kill the session , where session is taking longer than expected time.

Maximum sessions will be opened 32767.

Remember 1 to 50 are background processes, we can’t able to kill.

TO kill the session query is “ KILL sessionid or SPID”

Before killing any session, check with the user and then kill it.

65. How to run a query in multiple instances or multiple sql servers at a time?

Ans. By using the registered servers, we can achieve this.

Below are steps,

A) OPEN SSMS, Go to VIEW, Select registered services, Now registered services window appear.

B) Right click on local server group, Select new server group or new server registration,

Give the SQL SERVER INSTANCE NAME IN THE SERVER NAME


COLUMN, Click on Test. If the instance already created with the
name. Then server will be added in the registered services.

66. What are customized server roles?

Ans. Creating our own server roles are called customized server roles. Collecting the Combination of permissions
as per our requirement from the different fixed roles are assigning in to customized server roles. If we any login to
that customized server role, he/she are allowed to access the permissions of customized server roles. We can add
or alter or delete the customized server roles, but fixed roles we can’t. Customized server roles are introduced
from SQL Server 2012 onwards.

Below are the steps to create customized server roles,

Mostly DBA won’t create Customized server roles. Developers write a query they ask us to run.

a. Open SSMS, Expand security, Right click on server roles, select new role,

b. Give the server role name, owner is sa, click on server and select the required permission, add the
logins , who want to access, Click ok.

c. Customized role created.


67. What are database level roles?

Ans. The database-level roles are a group of security principals that are used to manage the permissions within
the databases more efficiently. There are two types of database-level roles. One is a predefined database-level
role, and another is custom database-level roles. The custom database-level roles can be created by the
database administrator or the member of the db_owner role. To see the permissions of database level roles

Use the query “ sp_dbfixedrolepermission “

The SQL Server database has 9+1 fixed database roles. Here also public is not a fixed role and public is the
default database level role for all the users.

a. db_owner
b. db_securityadmin
c. db_accessadmin
d. db_backupoperator
e. db_ddladmin
f. db_datareader
g. db_datawriter
h. db_denydatareader
i. db_denydatawriter
j. Public

a. db_owner:

A member of db_owner can do anything. If deny applied to


the db_owner, deny only work. A member of Db_owner
can add a user to the other database level roles.

b. db_securityadmin:
c. db_accessadmin: Members of
the db_accessadmin fixed database role can add or
remove access to the database for Windows logins,
Windows groups, and SQL Server logins.

d. db_backupoperator: A member of backup operator can run the check point on a particular
database.

e. db_ddladmin: A member of ddladmin can truncate


,rename a table.

f. db_datareader: This role is very important ,why because regular we are going to give these
permissions to the users. A member of data reader can read the data. Only select
permissions are available in the data reader roles.

g. db_datawriter: This role is very important ,why because regular we are going to give these
permissions to the users. A member of data writer can have delete, insert & update
permissions on a particular database.
h. db_denydatareader:

A member of deny_datareader, user cant read the data of a particular database.

i. db_denydatawriter: A member of deny_datawriter, user cant insert, delete, update the data of
a particular database.

j. Public: This is not fixed database level role

68. What are check points?

Ans. Check point helps to copy all the committed transactions from log file to datafile.

No one runs the check point. It’s an automated process.

There are two types of check points,

a. Automated checkpoint: Automatically every 60 seconds, committed transactions transferred from log file to
Data file
b. Manual Check point: it helps when you want to copy the committed transactions of log file to data file
manually. NO NEED TO DO THIS MANUAL.
Query for manual check point is “CHECKPOINT”

69. How to start or stop the sql server in Command prompt?

Ans. For Default Instance : Search command prompt, right click and select run as administrator

Enter the command to stop the sql server “ net stop default instance name”
Enter the command to start the sql server “ net start default instance name”

For named instance : Search command prompt, right click and select run as administrator

Enter the command to stop the sql server “ net stop mssql$named instance name”

Enter the command to start the sql server “net start mssql$named instance name”

70. What is orphan user & how to find orphan users?

Ans. user doesn’t have login, that user is a orphan.

When we delete any login with out removing the users of the database level, at that time users are orphans.

One more case, when we restore the database from production to non-production or from one server to another
server, users of that database are also orphans in the nonproduction or restored database server.

To track the orphans in a database, use the bellow query, Select the database on which the below stored
procedure you want to run

“sp_change_users_login report”
71. How to create login for orphan users?

Ans. by using usersid, we can recreate the login. To get the usersid (user security identification number) run the
query, “sp_change_users_login report”.

We have four methods to recreate the login by using existed orphan user

Method :1

Copy the user usersid, and create the new login by using this sid.

“Create login Anil with password=N’Sweety@12’ ,

Sid=paste the usersid , check_policy=off ,

check_expiration=off”

Method 2: If you have a login and user map both login and user by doing AUTOFIX METHOD.

EXEC SP_CHANGE_USERS_LOGIN ‘AUTOFIX’ , ’USER NAME’

Method 3 : if you want to create a new login and password for the user ,

EXEC SP_CHANGE_USERS_LOGIN ‘AUTOFIX’ , ‘LOGIN NAME’ , NULL , ‘PASSWORD’

71. How to give SQL Server agent permissions to a user?

Ans. By selecting the MSDB database and choosing the


SQL Server agent roles.
72. What is Locks?

ZAns. A Lock will be created when any transaction performed on the table .

Below are the types of Locks.

Shared Locks (S): These locks acquired by readers during read operations such as “SELECT”. Who ever writing the
select transaction on the table shared locks will be created.

EX: select * from emp where id=121

Exclusive Lock(X) : These locks acquired by writers during data modification operators such as Insert , Update &
Delete. These Locks prevent one object to be modified by the other sessions. These locks are always acquired and
held till end of transaction. Exclusive access means complete access. Till the end of the modify transaction, others
cant access the table.

Update Locks(U) : These locks are the mixture of shared and exclusive locks. when you run a modification
transaction, Till the searching of the columns sql server keeps shared lock . once column found, it will convert
shared lock to exclusive lock.

Ex : Update Mytable set column1=0 where column1 is null.

Now SQL Server put the shared lock on the table till searching for column1 is null. When eligible row found, SQL
Serve converts S to X.

Intent Lock(IS,IX,IU,ETC) : Intent Lock not a table level lock . It’s a range level lock. It wont keep the lock for the
entire table. It will keep the lock only to the particular range of the table. Remaining range can be accessed by the
other users.

Shared , Exclusive , update are table level locks. Where Intent lock is range level lock.

Ex : update emp set sal=sal+1000 where id=121.

Now SQL Server keep the lock for particular range i:e; is 1-1000 rows lock.

Remaining columns can be accessed by other users.

72. What is the difference between LOCK Vs Block Vs Dead Lock?

Ans. Lock : DB Engine locks the rows/page/table to access the data when user runs a query.

Blocking : When once person blocks the resources of another process then blocking happens. Below is the
example, User 1 executing the query on emp and still its running. Now user2 is trying to access the same table emp.
Now user1 query will block the user 2 query.

When ever blockings created we have to remove the blockings


manually.

First we have to find blockings by using below query,

SP_WHO or SP_WHO2 or

Select * from sys.dm_exec_requests where blocking sessions <>0

Or

Select * from master..sysprocesses where blocked <>0

Now we have to kill the blocked the session by using below query,

KILL Spid;(Server process identifier)

1 to 50 spids are server spids. We cant kill.

>50 spids are user spids. we can kill.


Always check which one is good to kill and then take the user approval. Then kill the session.

To see the what is the query running on the sessions, we use DBCC,

DBCC inputbuffer(sessionid);

Dead Lock : If 2 users having lock on 2 different tables , each user trying to access the other user table, Then the dead
lock will occur. In this , USER will not release the lock. When this happens, the sql server ends the dead lock
automatically choose the one query to run queries continuously and other user abort the transaction. SQL server abort
the user transactions, which is having least amount of resources to roll back the transaction.

Dead Lock Victim : The query which cancelled by sql server because of deadlock. That user is a dead lock victim.

Capturing dead locks : To capture the dead lock information in sql server error log, We need add two trace flags in
the start-up parameters.

Those are -T-1204 & -T1222


We can capture the dead lock errors by using profiler also.

Profiler : SQL Server Profiler is a tracing tool provided by Microsoft since SQL Server 2000 version. It is used
to trace activities and operations executed on a specific SQL Server database engine or Analysis Service to
be analysed later.
Open SSMS, Go to Tools, Select Profiler, Login to the instance, enter the name select the template type “TSQL_LOCKS”
, You can save to table or file , You can enter the end time to stop tracing the locks.

Now go to Events selection tab, Tick the errors and warnings, Locks. Click Run. Profiler start to trace the locks.

73. What is the query to see the list of logins?

Ans. select * from sys.sysusers

74. What are the different types of backups?

Ans.

a. Full backup : Full back up can take entire database backup that includes data file & log file. Once full
backup completed, It resets the DCM Pages.
b. Differential backup : Will take the backup of all the extents that has changed since last full backup,
which is having datafile and log file. With the DCM(Differential change map) page only , differential
back up can identifies the what are all the changed extents.
Interview question : how differential back up knows what are the extents changed since last
backup?
Ans. DCM Page helps to track the extents, that are changed since last backup.
c. Log Backup : It takes backup of the log file or transactions including committed and uncommitted
transactions. First log backup starts from last full backup and second log backup onwards it starts from
last log backup. It’s a kind of
chain system. Each log backup
has a unique LSN number(Log
sequence number) to restore
the log backups. If we miss any
of the Log file, LSN number
mismatched will occur. Then
we cant restore log backup
d. Copy_only backup : While we
taking backup, if we choose
copy_only_backup, DCM Pages
wont be reset. When you are taking the any backups with out automation, always choose the copy
only backup. Why because, if someone took the manual full backup without copy only option , the
automated differential will start from the manual full backup onwards. It breaks the LSN, it leads to
Chain break and restoration failed. So, When you are taking the manual backups, always choose the
copy only backup.
e. Tail log backup : When ever database is corrupted immediately, we have to take Tail log backup. The
first action we have to do after the database corrupt, take the tail log up. We can take tail log up only
with query,

“Backup log database name to disk=’path.trn’ with no_truncate “

f. File or File group backup


g. Stripped backup/Split backup : When we don’t have free space in single drive, to split the backup in to
multiple drives with the help of split backup. One backup can be taken to different locations. If any
one of the split back is missed, we cant restore the database.
h. Mirror backup: it creates the one more copy of backup for safety. If the original backup file is missed,
we can use the this mirror backup copy.
Mirrored backups cannot reside with other nonmirrored backup sets, hence with format option is
mandatory to mention.

Syn : backup database DBname TO disk=’path.bak’ mirror TO disk=’path.bak’ with format

i. Partial backup : partial backups are useful whenever we want to exclude read only file groups . A
partial does not contain all the file groups.

Syn : BACKUP DATABASE DBname READ_WRITE_FILEGROUPS,FG1,FG2 TO DISK=’path.bak’

j. Partial Differential backup: Is a differential backup for partial backup.

k. Cold backups : if backup is being taken for once specific database then
75. What are the media options in the backup?

Ans. There are two types,

a. Backup set : A single backup is called Backup set.


b. Media set : Collection of backup sets in to a single
backup file is called Media Set.

When we are first time taking backup, that backup file is


backup set.
If you are taking second time backup the same database with the same name in the same location and
selected the option append , now the backup file contains 2 backups. Now the same backup file called as
media set. While restoring it will select the recent full backup from the backup file only.

76. How to set default server setting for compression of backup?

Ans. Right click on server, go to properties, go to database settings,

Tick on compress backup. Click ok.

Now all the database back up default setting will be compressed. With out changing the set backup compression
type to compress backup, it will take the default setting as compressed.
Note : While running the backup, the transactions between the backup also part of full backup.

Ex : If a backup is started at 8 PM and going to complete at 10 PM. The transactions in between the 8 to 10 pm
also now part the backup.

77. What is recovery ,types of recovery,?

Ans. Recovery means how the database is recovering.

There are 2 types of recovery,

a. Restart recovery :Every time an instance is restarted/started the consistency of all the databases
including master, model, msdb and TempDB is checked. This process is an internal operation and
initiated just to keep the entire instance clean and with integrity.
Taking database offline/online involves restart recovery for the database.
Simply database engine checks the all the databases, whenever restarted the server or keeping a
database from offline to online. That is called restart recovery.
b. Restore recovery : As per backup strategy whenever a restore is started and recovery is done per
backup sequence. This entire process of recovery initiated manually is called as restore recovery.
Simply Whenever we restored a database, Database engine checks the integrity of restored
database.
78. What are the types of recovery models?

Ans. Recovery models are designed to control transaction log maintenance . recovery model control the
behaviour of the log file. Using the recovery models , we can the behaviour of the log file.

There are 3 types.

a. Full recovery model: When a database in full recovery model, it tracks all the 108 attributes of the
log file completely. So, We can take the log backups and we can achieve point in time recovery.
When a database in full recovery model, we can take full backup , differential , log backups & tail log
backups.
b. Bulk logged recovery model: it acts as a full recovery model, when there is no bulk inserts or bulk
transactions in the log file. If bulk operations are there, then all bulk transactions are minimally
logged. In case If you know bulk operations are going to happen on a database, keep the recovery
model as Bulk logged. If there is no bulk operations, its possible to restore point in time and if there
is a bulk operations, not possible to restore point in time in bulk logged recovery model.
When a database in bulk logged model, we can take full backup , differential , log backups & tail log
backups.

Interview question : how sql server know, which are bulk operations?

Ans. BCM( Bulk changed map) tracks all the extents, those changed by bulk operations.

c. Simple recovery model: With the help of simple recovery model, we can able to take only full &
differential backup. Log backup is not possible. Every 60 seconds log file will be deleted in the simple
recovery model by the help of check point in regular intervals.

In the organizations, mostly use full recovery model in the database.

When ever we change the recovery models of the database, we have to take full backup of that
database after changing the recovery model. Its must and should.

79. What is dirty page?

Ans. The changed or modified pages in the memory is called dirty page.
68.What is pseudo simple recovery model?

Ans. After changing the recover model, if we don’t take the full database back up – the database behave like old
recovery model. That behaviour of database is “Pseudo simple recovery model”

80. What are the scenarios , where restore the databases?

Ans.

a. When data base is corrupted ( Very rarely happens)


b. Data base refresh tasks.( Developers want to test their logic in the non – production environment, at
that time , DBA restore the production databases to non-production environment . Simply restoring
databases from prod to non-prod environment)
81. What are the recovery states?

Ans.

a. Restore with recovery : In case you have selected all the backup files to restore and there is no more
backup files is pending, then you can choose this recovery option. For the last or final back up , we
have to select this recovery option. If you choose this option, after completion of restore, database
comes to online and we cant restore further backups.
b. Restore with no recovery : till last backup to restore, we have to select this option. In this recovery
state, database wont comes to online. Once the last back up selected and changed the state to with
recovery, data base comes to online after restore.
c. Restore with standby : if we restore the database with stand by, It only allowed to read operations
on a database.
82. How to get the data base online , if you have restored a database with no recovery?

Ans. use the query “ restore database db name with recovery”

Note : We can restore a database from lower sql version to higher sql version and same version to same version.
But, we cant restore a database from higher version to lower version.

83. How to restore a database from one sql server to another sql server or production to non production or once
instance to another instance?

Ans. We can restore a database from lower sql version to higher sql version and same version to same version.
But, we cant restore a database from higher version to lower version.

a. First copy the backup files from the production server and copy in to non-production server.
b. In the organizations, we will be having shared paths, where we can keep these backup files to access in
the production server or else Ports should be open between production and non-production servers,
then we can copy and paste the backup files directly. To open ports, we have to request network
team.
c. Open SSMS in non production environment, right click on databases, go to tasks, select restore.

d. Select the device , choose the path of the backup files in the database column, give the database
name.

e. Go to files tab, here we have to change the path of the restore as for mdf, ndf & ldf. Why because
those paths , which are from the production environment . We don’t have those paths in non-
production environment. Now give the path , in which path we want store the data files and log files
after the restore or else tick the relocate option , where sql server will create a new path.
f. Go to options tabs, select recovery state. Click ok.

84. Is it possible to take full, differential , log backups on system data bases?

Ans. Recovery model for TEMP DB is always simple only. We cant change it.

System data Full Log


bases backup Differential backup
Master Yes NO NO
Model Yes Yes Yes
MSDB Yes Yes Yes
TempDB NO NO NO

85. What is job in SQL Server?

Ans. Job is an automation process. A job is a collection of steps. Scheduling a script to run. A job always depends in
the script.

Mostly we have 5 types of jobs , we can automate.

a. Backups
b. Restore (Very rarely)
c. DBCC
d. Rebuild indexes
e. Reorganizing indexes
86. How to configure a full backup job?

Ans.

a. Open ssms, expand SQL Server agent , Right click on Jobs, select new job,
b. Give the Job name, Give the owner as “sa”

c. Go to steps tab, Create new,

d. Enter the step name, choose the database as master, enter the full backup query in the empty space,
“backup database dbname to disk=’path.bak’ with init,format”
Now click on the parse to find out any syntax errors.
e. Go to advanced tab, choose on success action (If step 1 succeeded what to do)- mostly choose go to
next step , choose in failure action(if step 1 failed what to do)- mostly choose the quit the job
reporting failure. Give the retry attempts and interval(not mandatory) , create notepad and save it .
give this notepad path in the output file column. This can be helpful , if job fails at a certain point of
time- we can open that note pad and check the error. Click ok. If you want to add one more step to
take one more backup , do the same process.

f. Go to schedule tab, create new, give the name , select the schedule type, tick enabled, click ok.
Job created.

When ever you want restart the job , check the duration of the job completed. It its taking more time to complete the
job like 4 to 5 hrs inform to client, why because it may slow down the server. Performance issues.
Note : if any step is failed in the job, after rectifying the error- don’t start the job from beginning. Start from the failed
step. Like below.

Right click on created job, click on start job at step, Select the step id where job has failed and click ok.

To find out the step id of failed job, right click on created job, go to view history , expand the line where step is in “X”
mark. Below to that error will be displayed. Once rectified the error, start the job from that particular step.

87. What is an alert in sql server agent?

Ans. You can use the Database Alert Monitor to identify memory problems in good time, to check the
security of your database system, and to monitor performance. If data collection methods are periodically
scheduled, alerts are automatically updated, and forwarded to the monitoring tree.
88. How to create a database mail?
Ans. To get the alerts from the sql server agent to the user, we need a database mail. As of now we
don’t have outlook mail. S0, below example for gmail.
a. Open SSMS , Expand management , right click on database mail, select configure database mail,

b. Click next, select setup database mail , click next,


c. Give the profile name , click on add button,

d. Enter the account name , give the mail id, where you want the alerts, give the smtp(simple mail
transfer protocol) every organization has smtp server for mail purpose. Gmail smtp is
“smtp.gmail.com” and give port number 587 for gmail. In the organization , we give outlook details
only. Outlook port number is 25. In the organizations, we will be having scripts to create the database
mail. If we don’t have the scripts, then we have to go like this.
Tick – this server requires secure connection. Select basic authentication, give user name and
password. From this basic authentication only mails will be send. Click ok. Click next.

e. Tick the public, and default profile YES. Click next.


f. Configure the parameters. Click next

g. Click finish.

h. Success message

i. Now we can check the database mail is working or not by


using the Test email option in the management.
j. Gmail wont allow the messages from unsecured emails. So, we have to turn off one security in the
gmail that is “Less secure app access”. We have to turn on.

i. Right click SQL Server Agent and select Properties

j. Select Alert System in the left pane


and do the following:

 Check Enable mail profile


 Verify Mail system is Database
Mail
 Verify Mail profile
is SQLAlerts that we discussed
above
 Check Include body of e-mail
in the notification message
 Click OKto save settings.
 Restart SQL Server Agent to
Activate Settings
89. What kind of monitoring tool used in your current organization? (interview Question)

Ans. We are using SQL server alerting system and SCOM alerts for windows level.

We can use sql server alerting system or else we can use third party tools like Spot light , Fog Light , Idera etc.

We can configure sql server alert system by using database mail configuration

90. What is an alert?

Ans. There are 3 types of alerts.

a. SQL Server event alert : When we know the exact error number, we can configure event alert. Below
are few error numbers.
Error Description
18456 Login failure
1105 Data File full
9002 Log file full

b. SQL Server performance condition alert :


Actually its not an event or error, Its going to
alert us before the error comes. Based on the
threshold limit , we can set the condition alert.
For Example , Creating an alert for data file full
– When datafile reaches to 90% of size its
going to alert us. One more example, When
CPU Usage reaches 75% alert will come. We
will fix the issue after the immediate alert.
Based on our threshold limit, its going to work.

c. SQL Server WMI Event alert : WMI(Windows management instrumentation) . It Tracks all the DDL
Commands. Mostly we wont use this alert. This alert we can enable based on the query. For example.
Who deleted the an object like that we can track and we receive the email.
91. How to create an alert system?

Ans.

a. Open SSMS, Expand SQL Server agent, Right click on operator, create new operator.

b. Operator is a recipient of the error. Operators we can create with out mail configuration also. But we
wont receive mails. So, After the successful mail configuration only alerts can send the operators.
c. Enter the name of the operator , Enter mail address of recipient in the Email Name , Click ok.

d. Operator created.
e. Now right click on alerts, select new alert.

Setting Type SQL Server event alert:


Enter the alert name, Choose the type of event, select the database, enter the error number, enter
the message text when error comes,

Setting Type SQL Server performance condition alert :

Enter the name , choose the type , choose the object , choose the counter , Choose the

instance(_Total – selecting all the databases) , Counter type , value,

f. Go to Response tab, Click on notify operators, Select the operator, Tick Email
g. Go to Options , Tick Email , Enter the text in empty space, Click ok.

d. Alert Created for login failure successfully.

Few examples :

Creating alert for CPU usage reaches 90-%


Creating alert for Datafile size reaches 90%

Creating alert when blockings morethan 4

92. How to setup Email alert for a backup Job?

Ans.

a. Expand SQL Server Agent ,Expand Jobs , Select and right click the already created job and go to
properties,

b. Go to notifications, Tick Email, Choose the operator, Choose the reason, Click ok.
93. What are general alerts , which is created in your current organization?

Ans.

a. CPU alert
b. Memory Alert
c. Data file size alert
d. Log file size alert
e. Blocking alerts(VV IMP)

94. What is T-SQL?

Ans. T-SQL is Transact structured query language. By using T-SQL, We can modify, delete, select & update the data
in the database. There are four languages in T-SQL.

a. DDL(Data Definition language) :


b. DML(Data manipulation language)
c. DCL(Data Control Language)
d. TCL(Transaction Control language)

95. What are the data types in SQL Serer?

Ans. The type of data which users provided to a specific column is called a Data Type.

There are 2 types of data types.

a. System defined data types : SQL Server already contains some data types called System defined data types or
predefined data types or built-in data types. System defined data types are again defined in to 4 types,
a) Numeric data types : used to provide numeric information for the columns. These includes
b) String data types : used to provide Characters for the columns, These includes,

The difference between Char and Varchar is Char is a fixed length data type where Varchar is a Variable
length data type.

Ex:

c) Data time data types : used to provide date & time oriented information for the columns . These
includes,

d) Special data types : used to provide miscellaneous information to the columns . These includes,
b. User defined data types:

96. What is upgrade?

Ans. Upgradade means simply upgrading the SQL Server or instance from lower version to higher version. Mostly
people go for migration only not upgradation in the organization because of lot of challenges in upgradation.
Before doing the upgradation or migration, we have to run “Database migration assessment tool” to asses – what
kind of issues will face. After that we can start upgrade.

We have two types of upgrade :

1. IN Place upgrade(Upgradation)
2. Side by Side upgrade(Migration)
1. In Place upgradation: IN Place upgradation lot of challenges is there for upgradation but its easy.
In Place upgradation overwrites the existing SQL server or instance. We have to choose IN Place upgradation ,
only when the gap between lower version instance to higher instance is 7 years.

The challenges in IN Place upgradations are below


a. We cant directly upgrade from very lower version to very higher version in a single
shot. It means, The gap between lower version & higher is more than 8 years,
direct upgrade is not possible. We have to upgrade split the upgradation.
For Example : if the client is requested upgrade my 2008 Instance to 2019 version
First , we have to upgrade 2008 instance to 2012 and then from 2012 to 2019.
Or else 2008 to 2016 and then 2016 to 2019.So, Its not possible upgrade from very
lower version to very higher version in a single shot.
b. One more challenge is, Currently 2008 instance running on windows 2003 server.
Customer is requested to upgrade the 2008 instance to 2019 version. As we
already discussed, Each sql server version can support -7 to +7 windows server
machines. So, In this case- Upgradation of 2008 to 2019 version is difficult to
upgrade because of windows server is 2003 version. So, first we have to upgrade
windows server. Windows server also we cant upgrade in a single shot from very
lower version to higher version. We have to split in to 2 parts. After the windows
server upgradation only we can start sql server upgradation.
c. After the upgradation, we cant go back to the lower version if you are facing any
compatibility issues or any other. If you like it or don’t like it, we have to use the
upgraded server only. We cant down grade.
d. Down time of instance is also high in upgradation
e. We can upgrade to the same edition only. Like Developer edition to developer
only like that. We cant upgrade from developer to any other. Same way for all the
editions. For example, Customer is requesting to upgrade 2017 SQL server
developer edition to 2019 enterprise edition. First we have to upgrade edition
from developer to enterprise and then we have to upgrade the instance or else we
can upgrade the 2017 version to 2019 version and then we have to upgrade the
edition from developer to enterprise.

In this we have another 2 upgrades,


a. Version Upgradation : Upgrading the versions of SQL Server is called Version Upgradation
b. Edition Upgradation : Upgrading of Editions of SQL Server is called Edition Upgradation.

96. What is the use database migration assistant?

Ans. We can check what are issues will face before if we do any
migration.

Below are the steps to use migration assistant,

Step 1 : Open database migration assistant application

Step 2 : Click on new , Choose assistant, Give the name , Choose


assessment type database engine, Select the source server type and
Target server type. Click create.

Step 3 : Add the instance name and login Like

‘Computername\instancename’

Click assessment. Now we can see if there any compatibility issues.


97. How to upgrade SQL Server?

Ans. Below is the Example of upgrading SQL Server 2017 developer edition to SQL Server 2019 developer edition.

Whatever precautions we took while doing the patching, same precautions we have to take.

a. First Check the what is the version and edition of the installed instance by using the query
“select @@Version” – Below is the 2017 version , build no 14 and developer edition

b. Open SQL Server SQL Server 2019 developer


edition setup folder , Right Click on setup.exe,
RUN as administrator.

c. Go to installation tab, Choose the upgrade from a previous version of sql server.
d. Specify the developer edition , click next.

e. Tick the Licence agreement , click next.

f. After 3 times next, Instance selection window will come like below.
g. Choose the instance, which you want to upgrade and click next. Below I have selected MSSQLSERVER
instance.
h. Features selection window will come. No need to select any features. By default, what all are the
features selected in the 2017 version, the same will be selected and same features will be upgraded to
2019. We cant even uncheck the features also. Click next.

i. Full text upgrade window, choose Import option , click next.

j. Click on upgrade.
k. Upgradation completed.

l. We can check upgraded version number in the SSMS.

98. What is migration?

Ans. Migration means creating the same environment of already existed instance. For migration there should be a
target and destination. Migration is a very long process but its safe process. We normally do the migration, when
there is any database refresh tasks & upgrading the sql server from one version to another version. In Migration,
We can upgrade SQL Server to any version & any edition.

Migration is simply 1st step : Creating the same environment like target in the destination(Windows server , SQL
Server of required version)

2nd Step : Take the database backups of target

3rd step : Restore the backups in the destination


99. How to open another windows server drives in the current windows server?

Ans. Open run , type the command \\IPADDRESS of server\drive letter$

Example : \\192.168.0.102\C$
100. What are steps for migration?

Ans. Below is the example of migration from SQL Server 2017 to SQL Server 2019.

a. Install the SQL Server 2019 in the destination.


b. Took the backup of all the user databases from the Target sql server 2017 by using the maintenance
plan.
c. Copy the backup plans from target machine to destination machine.
d. Restore the backups in the SQL Server 2019
e. Now to export the logins from target to destination, that can be achieved by creating a stored
procedure “SP_HELP_REVLOGIN” in the target server sql server 2017.

f. Search the script in the google for “SP_HELP_REVLOGIN”. This stored procedure script out all the
logins with password. By using the script create the stored procedure and run it. Don’t copy from
third party websites , use Microsoft. Don’t blindly copy every thing, read the script and check whether
there is any links or anything.

g. Paste the script in the target server and run


h. After run the script, it will create 2
stored procedures
i. Sp_hexadecimal : Converts the
passwords in to encryption
ii. Sp_help_revlogin
i. Execute the STORED Procedure in the
target,

j. Copy the output message


and paste it in the query
window of destination
server. Run the query.

k. We will get few errors, because already default logins available in the destination server. if you don’t
want the errors, delete the default login queries.
l. After this step, same logins will be created in the destination.
m. Now we have to copy the jobs from source to destination.
n. Select the jobs, right click , choose script job as, select create to , New query window editor

o. Query window will open like below, Copy this script and paste the script in the query window of
destination server.
p. After paste the script, Change the owner name in the script to “sa”

q. If you have created any job with alerts, you have to create the same notify email operator in the
destination server. In the below screenshot, there is a dba operator.

r. Create the same operator in the destination. Expand sql server agent , right click operators, select
new, Create new operator.

s. Jobs created in destination server


t. Now we have to change the compatibility of all the databases in the destination server.
Run the stored procedure “sp_helpdb”. It will show the compatibility of databases. Here its showing
the compatibility of databases in destination server as 140. This is source compatibility .

u. Now we have to change the compatibility of databases manually. By using the query

“ALTER DATABASE dbname SET COMPATIBILITY _LEVEL=COMPATIBILITY NUMBER”

Ex:

v. Run the queries and compatibility will be changed.

w. Migration completed.
x. Don’t Decommission of old server Immediately. Wait for 2 to 3 days, if there is no issues we can
decommission.
101. How to setup Active Directory in the windows server?
Ans. Active directory setup is windows team work. DBA won’t create any active directory.
To configure the HADR , We need a domain, So, we are creating the Active directory setup.
Every user in the organization is the part of Active Directory only. If any user want to access the server, Logins will be
created in the active directory. In the active directory , we have different groups. Each group has a group policy. Policy
nothing but permissions.

When a new person joined in a company, a login will be created in the active directory setup and they will set the
permissions to access the servers, which they will work. With the help of active directory, A person can access all the
servers with out created any new logins.

Based on the groups in the Active directory, user can access to the only those particular servers.

Setting the Active directory setup n my local machine to practice:

Step 1 : Click on add roles and features

Step 2 :Choose role based , click next

Step 3 : select active directory domain services, Click next

Step 4 : Click install.

Step 5 : Now we have to configure active directory setup after the successful installation.

Step 6 :Click on the FLAG symbol and promote the server to a domain controller

Step 7: After this , select add a new forest and give the name of the domain like IBM.COM, WIPRO.COM etc, CLICK
NEXT
Step 8 : Enter the new domain password, Click Next.

Step 9 : enter the net bios name – What ever we mentioned in the root domain name in the above screenshot, Enter
the same name with out ‘.com’ Like IBM. It will pick automatically. Click Next.

Step 10 : Install

102. What are the steps to follow to create continuous connections between Active directory , NODEs?

Ans.

Step 1 : Turn off the Windows Firewall in the server

Step 2 : Create a Manual IP Address . Open network connections by using RUN “ ncpa.cpl”. Right click on Ethernet, go
to properties, Select IPV4 , click properties, In the general tab- Choose ‘use the following IP Address”, and enter the
IPADDRESS like below,

Give different IP address for Active Directory and Nodes

Ex : Active Directory : 10.10.10.100

Node1: 10.10.10.101 , Node 2 : 10.10.10.102

Once we fixed the IP address, then servers can communicate always each other.

We have to fill preferred DNS server as “Active directory IP address” for all NODES.

No need for Active directory.

Step 3 : Change the computer name as “ActiveDirectory” , “NODE1” , “NODE2”. In the Workgroup column of NODE1
and NODE2 give the IBM.COM as group and click ok. Now NODE 1 & NODE2 will be added in the Active Directory.

103. How to change the location of user database in SQL Server?

Ans. To change the location of a database, we have to move datafile & log file of a database.

Step 1 : Run the query “select * from Sys.sysaltfiles” to know the name & location of the datafile, Logfile of each

database.

Step 2 : copy the path of datafile & logfile to copy files from old location to new location in the last step.
Step 3 : Write the Alter Query for moving data file , “ALTER DATABASE dbname MODIFY FILE
(NAME=’DATAFILENAME’ , FILENAME=’NEW PATH.MDF’)
Write the Alter Query for moving LOG file , “ALTER DATABASE dbname MODIFY FILE (NAME=’LOGFILENAME’ ,
FILENAME=’NEW PATH.LDF’)
Execute.
Step 3: Now path of the database will be changed and we can check in “SELECT * FROM SYS.SYSALTFILES”
Step 4 : Now keep the database offline.
Step 5 : Now copy the files physically from old location to New location.
Step 6 : Now bring the database online

104. How to setup log shipping?


Ans. In log shipping , A database is going synchronize between the servers. Log shipping can be done up to the
Database level only. We have to maintain same data between the servers.
Simply Log shipping means, Shipping of the LOG backups from primary server to secondary server.
Log shipping works based on the backups. We can keep 4 secondary servers for a single database.

In Log shipping , We can restore the backup in the secondary server with No Recovery and Standby mode.
With No recovery, we cant access the database. With Stand BY, We can read the data of the database

We will have 3 jobs in the log shipping:


a. Backup job in Primary server
b. Copy Job in secondary server
c. Restore job in secondary server

To setup the Log Shipping, We need the Shared folder between the servers. One is in Primary and one is in secondary
server.Below are the steps to create shared folder,

Step 1 : Create a folder, Right click properties, go to share tab, Click Share, Type everyone, Click add, permission level
change to Read/Write, Click ok. To know the shared folder lists, We can use the RUN command “\\Computername

Below are the steps to setup log shipping,

Step 1 : Open the primary server, Select the database which you want to log shipping, Right click, go to properties,
select Transact log shipping option, Enable this as primary database in log shipping configuration.
Step 2 : Click on backup settings, Enter the Shared folder address in the network path , Enter the local path Shared
folder address in the second column. Setting the automatic deletion of older backups. Schedule the back job time.
Click ok.

Every job name in log shipping starts with “LS” only Like LSBACKUP_Databasename

Step 3 : Add the secondary server instance by clicking add option, Click connect, select the secondary server, login

Step 4 : Choose the option based in requirement,

a. If we don’t have created the same database in the secondary server and we don’t have full back up of
primary server choose the 1st option
b. If we don’t have created the same database in the secondary server and we have full back up of primary
server choose the 2nd option
c. If we already restored the database in the secondary server, choose the 3rd option.

Step 5 :go to copy files tab, and give the shared folder address or local secondary shared address folder where we
want to copy the backups. Choose the time period to delete the old backup files. Schedule the Job timing.

We can give \\SAILESH-DEKSTOP\Sujithshare


or

C:\Sujithshare
Step 6 : Go to restore transaction log Tab, Select the restoring mode whether No recovery or Stand by. Tick the
Disconnect users when selected stand by. Schedule the restore job. Click ok.i

Step 7 : If we have another server, we can choose monitor server also.

Step 8 : Click ok. Log shipping will be created with 3 jobs – 1. backup Job in primary server, 2. Copy & Restore Job in
Secondary server.
Other important information of log shipping:

104. What are steps to failover the Log Shipping?

Ans. Fail over means , When primary server is down bringing the secondary server online is called failover.

Below are steps to failover the log shipping,

Step 1 : Took the Tail log backup of primary server database

Step 2 : Stop the restore Job in the secondary server

Step 3 : Check what are the backups pending to restore in the secondary server from primary server

Step 4 : Restore the pending backups

Step 5 : Restore the tail log backup with Recovery.

Step 5 : Secondary server database will come online.

Step 6 : Now will do reverse log shipping- Secondary server will acts as primary, Primary server acts a secondery
105. How to check the status of the Log Shipping ?

Ans. Right Click on the server , Go to rep orts, Choose Standard Reports, select Transaction log Shipping status.

If we select primary server log shipping status it will show only Backup job status.

If we select Secondary server log shipping


status it will show copy job and restore job
status.

106. How to connect multiple instances of different windows server machines in a single windows server?

Ans. By activating the SQL Server Browser services, we can connect.

Below are the steps,

Step 1 : Open SQL Server configuration manager

Step 2 : Go to SQL Server network configuration, Enable the TCP/IP.

Step 3 : GO to SQL Server Services , Start the SQL Server browsing services.

107. In which edition , we don’t have sql server agent?

Ans. Express edition. Log shipping also not possible.

108. How to access a folder of another windows server in our computer?

Ans. By using RUN command \\IP Address\drive letter$ or \\computername\drive letter$


109. How to Trouble shoot log shipping failure?

Ans. In what cases, Log shipping will break.

a. When the LSN number mismatch.

b. When any new file group created with manual path

110.
What is reverse log shipping?

Ans. Changing the Secondary server to primary and primary server to secondary. Reverse log shipping will do when
there is failover.
111. What is Mirroring?

Ans. Maintaining the same copy of database in another service is called Mirroring. To configure the Mirroring, version
and edition should be same in both the servers. To configure the mirroring, Database should be in Full recovery model.
Servers should run in the same service account. We can use different service accounts but using same service account
for both the servers is good practice. We have to keep same database name in the both the servers. In Mirroring, we
have only NO Recovery mode for restoring. We don’t have stand by mode used in Log shipping. So, We cant able to
read the data of the secondary server. In Mirroring, Primary server called as principal and Secondary server called as
Mirror. Mirroring can be created only to the 10 databases of a sql server.

We don’t have jobs in mirroring, Data will be transferred to another server by using 2 modes. Synchronous mode and
Asynchronous mode.

a. Synchronous Mode : If we run any transaction in the principal server, first the transaction will go to mirror server,
mirror server sends back the acknowledgement and then the same transaction will apply on principal. Automatic fail
over can be done in synchronous mode only. Always both databases sync is possible.
In Synchronous mode , we have 2 modes.

1) High Availability mode : In this we have 3rd server called witness server, which helps to automatic fail over of
servers. Witness servers always monitor the principal and Mirror, if principal goes down- witness brings the mirror
server online with out any manual activity. This automatic process is called Automatic failover.

2) High protection mode : In this we don’t have witness server, So automatic failover not possible. When
principal server goes down, We have to fail over manually from Principal to Mirror.

b.

Asynchronous Mode : If we run any transaction in the principal server ,it apply on the principal first and then
transaction applied on the mirror server. Automatic fail over not possible in asynchronous mode. In this case, with out
verification, whether transaction applied in the mirror or not – Transactions will be applied continuously on the
principal. In this mode, there is data difference. Chances data loss will be there. Asynchronous mode is faster than
Synchronous mode.

In Asynchronous mode, we have only High performance mode.

1) High performance mode : In this mode, we don’t have automatic fail over .
112. how to setup Mirroring?

Ans. Below are the steps ,

Step 1 : Take the Full and log backup of Principal server

Step 2 : Keep the same service account for principal , Mirror & Witness servers.

Step 3 : Give the SYSADMIN permissions to the service account in the all the 3 servers.

Step 3 : Restore Principal server database backups in Mirror server with NO recovery.

Step 4 : Right click on the principal server database, go to properties, select mirroring.

Step 5 : Click on Configure security, Click next, if client is requested for automatic failover, then only select yes for
witness server, Click next.
Step 6 : It will ask for the port number, The default port number for mirroring is 5022. This number comes
automatically no need to change or update. Click Next.
Step 7 : Now connect to mirror instance, here the port is 5023. Click Next.

Step 8 : Now connect to Witness instance, here the port is 5024. Click Next.
Step 9 : It will ask for the service account names for the all the 3 servers. If we using same service account for all the 3
servers at the beginning, no need to give any thing here. If different service accounts, then only we have to give the
name of the service account. Click next.

Step 10 : Click Finish .


113. How to fail over the Mirroring?

Ans. When the mirroring created the witness server, we need to do failover. Witness server automatically failover the
mirroring with the help of synchronous high availability mode.

If there is no witness server, we have to manually failover the mirroring. Below are the steps,

Step 1 : Right Click on principal database, go to properties, select mirroring.

Step 2 : Click on failover

114. How to monitor the Mirroring?

Ans. Right Click on Principal Database, go to tasks, select launch database mirroring

Below is the mirroring monitor


115. What is Replication?

Ans. Replication is the concept of transferring the data from one server to multiple servers. It mainly used for
reporting purpose. In replication, we can transfer all tables or only few tables or only few columns from few tables.
Replication is a object level concept. Replication increase the performance of the database. Replication creates a same
database in destination server, Once server used for production and one server used for reports. Below is the
example.

In Log Shipping, With the help of Stand by mode- We can take the reports but not possible to take continuously.

In mirroring, There is no concept of taking reports. Not at all possible.

In Replication, we can take the reports continuously.

Log shipping & Mirroring is database level concept, Where replication is table or object level concept.

Replication is not a high availability concept. Why because, we wont transfer all the tables or objects of the data to the
secondary server and we won’t use replication for High availability. Here, we cant use secondary server for failover.
Why because, We don’t have all the data of primary server in the secondary server.

In replication source server called as Publisher and destination server called as Subscriber. In between the primary and
secondary, We use another server called Distributor.

a. Publisher – Source server- The database which we used for transfer the data is called Publication database.

b. Distributor – Acts as a mediator b/w Publisher and Subscriber- it receives the data from publisher and transferred to
Subscriber.

c. Subscriber – Destination Server- The database which we used to receives the data is called subscription database.

In Replication, We called tables as Articles.


In Log shipping & mirroring, we took the backup of primary server database and restored in secondary server to
initiate the process. Where in replication By using snapshot process the initial data from publisher will be transferred
to Subscriber.

Snap shot process scripts all the objects from publisher and will be executed the scripts at subscriber. By using
BCP(Bulk Copy Process) the data will transfer from publisher to subscriber.

Snapshot will create tables in the subscriber without data. BCP transfers the data to the tables.

Snapshot process will create only the empty tables in the subscriber and with help of BCP data will be transferred to
the tables.

116. What are types of Replications?

Ans. There are 4 types of replications ,

a. Snapshot Replication

b. Merge Replication

c. Transaction Replication

a. Snapshot Replication : it will take entire data as an image and then it will transfer from publisher to
subscriber. This will be used when we have less data changes in publisher side. In snapshot replication, Data will be
transferred via Network(Internet).

Below is the example :

A database which contains 500 gb data. We took the snapshot replication and transferred the data to subscriber with
the network help. Another 100 MB of data has been added to the publisher. Now again we took the snapshot
replication, Now snapshot replication will take again the entire database image instead of 100MB. This time , 1 GB
data has been added to the publisher. We run the snapshot replication, it took the entire database image again
501.1GB and transferred to subscriber. Here , we have an disadvantage with the snap shot replication is every time
snap shot replication took entire database as image when ever changes in the publisher. It took all the resources of
network eery time. The other process will be slow because of this. That’s why, We use the Snapshot Replication only
for the databases- where changes is very less on the publisher. For example, Gold price changes only once in a day.
Here we can use snapshot replication, why because only one-time changes in the publisher. We run snapshot
replication once in a day.
b. Merge Replication: It’s a bi directional replication. Bi directional means data can be modified in the subscriber level
also. What ever data modified in the publisher will be transferred to Subscriber and at the same time, What ever
modified in the subscriber also will be transferred to subscriber.

In merge replication, couple of subscribers may or may not connected continuously to the publisher. But whenever
they connected to publisher, the data will be interchanged.

The disadvantage in Merge replication is continuous data transferring is not possible. Why because couple of
subscribers may or may not connected to publisher.

C. Transaction Replication : By using Transaction replication , we can transfer data continuously from publisher to
subscriber. What ever records will be there in the publisher the same data will be in the subscriber.

To initiate the Transaction replication , there are 3 agents,

1) Snapshot agent : To initiate the replication. Initial data of publisher will be transferred to subscriber.

2)Log reader agent : This agent takes the data from publisher and applied to the distributor db

3)Distribution Agent : this agent takes the data from the distributor and applied to subscription db.
snapshot agent will initiate the transaction replication, after that what ever modified will be transferred to subscriber
with the help of log reader & distribution agent . Log reader agent and Distribution agent runs continuously to transfer
the data from publisher to subscriber.

We have another concept “ Transactional with updatable subscriber “ in the transaction replication. With this we can
modify the data in the subscriber. we have agent called “Queue reader agent”. This agent takes the modified data
from subscriber and sends to distributor db. Now distribution agent sends the data from distributor db to publisher.

117. What are Indexes?

Ans. Mainly Indexes are used to improve the query performance. Index Structure is like a balanced Tree Like below.

When there is no index, SQL server search each and every page to get the data. With the help of INDEX, SQL Server
directly identifies the required page with out any delay.

Scanning : Searching each and every page to get the data is called scanning.

Seek : Directly pointing the page , where requested data is available without searching all the pages called Seek.

There are 2 types of indexes,

a. Clustered Index : Clustered Index will be created when we place a primary key in the column. Primary key
can be placed only to one column of the table. In Clustered index the leaf level pages contain data. That’s why, when
we run the query, we get results quickly. We can able to create only one clustered for one table.

Primary Key : Primary key does not accept duplicate values and null. So, when we place primary key to a column, The
data will be unique.

b. Non-Clustered Index : Non clustered index will be created when we place unique key in a column. We can
able create 999 non clustered indexes in a single table. In Non-clustered index, the leaf level does not contain any
pages. Non clustered index has a pointer to Clustered index for getting data. If there is no clustered index, Non
clustered index depends on the data pages available in the disk. Non clustered Index will improve the performances of
other columns.

Unique key : It won’t accept duplicate values and accept only one null value for a column.

In a table, We can create one clustered index for one column and rest of the columns we can create non clustered
indexes.

When there is no Clustered index on a table then there is no use of creating NON Clustered indexes.
118. How to see the performance of a query?

Ans. Optimizer creates a plan to execute the query in a optimal manner. That plan is called Execution Plan.

There are 2 ways to find out the execution plan,

a. Actual Execution Plan : It will execute the query and it will provide the plan of executed Query.

To enable the Actual Execution Plan, We can use Short cut Ctrl+M or we click on the icon “Display Actual
execution plan”

b. Estimated Execution plan : With out Executing the query , it will provide the plan.

To enable the Estimated Execution Plan, We can use Short cut Ctrl+L or we click on the icon “Display Estimated
execution plan”

After enabling the execution plan, Execution plan tab will come like this. We can click on that tab and we can see the
plan of the Execution of a query.

If you want to see how many pages a query reads to retrieve the data, we have to enable “SET STATISTICS IO ON” .

Now we can see in the messages tab

Before After SET Statistics IO ON


We have to read execution plan from right to left.

To see the all the costs of the query, Just put the cursor on the table.

Its used SCAN process because there is index on


the table.

We will see mostly Estimated operator cost only. Estimated operator cost is combination of CPU , IO & Memory.

In the above image the operator cost is 1.05884 and rows read is 200000 and actual number of rows is 1.

It means to find 1 row, SQL Server reads all the 200000 rows. Due to this operator cost is increased.

Now to reduce the Operator cost and Rows read, We create Clustered index on a unique column of a table.

Syn: CREATE CLUSTERED INDEX name ON tablename(column name);

Ex : CREATE CLUSTURED INDEX CI_SALES ON sales(id);

Now we can see SQL Server used SEEK process because we created the Index.

Now we can see in the below screenshot the operator


cost came to 0.00323 and number of rows read and
execution is one. For to retrieve one row of a table, SQL
Server reads only one page and executed one page by
using Clustered index.
Normally Indexes will be created on the columns , where column name used more after the WHERE condition.

For Example, In the below Query PRICE column used after where condition. So, We will create Index on the PRICE
Column.

Select * from sales where PRICE=50;

We reduced the Operator cost of query by using Clustered index. In case, The user runs the query by using another
column instead of Clustered index column. Then, Again operator cost and logical reads will increase. To avoid these,
we will create NON-Clustered indexes on the other columns.

Below is the example , where Query executed with NON Index column and used the SCAN process to retrieve the data.

Operator cost is 0.84 and reads 20000 rows to retrieve 1 row.

To avoid this, Now we will create NONClustered index on the Executed column.

Syn : CREATE NONCLUSTERED INDEX name ON TABLE NAME(COLUMN NAME)

Ex: CREATE NONCLUSTERED INDEX NCI_SALES ON SALES(PRODUCT);

Now if we see operator changed from SCAN to SEEK process and operator cost came to 0.003 and rows read and
executed 111 only. It means, What ever rows we requested the same pages has been SQL Server pointed directly and
retrieve the data.

NON Clustered index pointed to clustered index


to retrieve the data.
In the above screenshot , there is key lookup. Key lookup is not good sign, it takes more operator cost to perform. So,
We have to eliminate the key lookup. Key look up will be created automatically , when any one of the column of a
table don’t have the index on the retrieved the data.

In the below query, Index not created on price and date transaction. In this case, Key lookup will be created.

To eliminate the key lookup, we have to use covering index. Covering index means, We have to add these columns
to the existing non-clustered index. Covering index will cover all the columns with one non clustered index.then key
lookup will be eliminated automatically.

Below is the procedure of covering index,

Step 1 : Expand the database, Expand tables, Expand the required table, Expand indexes , select non clustered index,

Step 2 : Right click properties, General tab, click add,


Step 3 : Tick the columns and click ok.

Now run the query and we can see in the below screen shot , Key lookup eliminated.

In the above scenario, we know on what columns clustered index & non clustered indexes required.

But in the organization , so many users runs different queries on different tables and columns.

We cant do manually like above. Why because, we don’t have track on that.

Without knowing on which column the user is running the query, we cant create index.

To achieve this, we have profiling and DTA(Database tuning advisor).

Profiler : profiler capture/trace the queries run by the users. Extension of profiler is “.trc”. trc means trace.
We have to give profiler output to DTA as input.
Profiler output = DTA Input
DTA : It will analyse the input and provide the recommendation of indexes.
Now will see practical of using profiler and DTA.
Step 1 : OPEN SSMS, Go to tools, Select SQL Server Profiler.

Step 2 : Login to the instance.

Step 3 : Enter the trace name, select the template from the list “Tuning”, Set the maximum size and enable the file roll
over option.Tick the SAVE file and give the location where you want save the output.

By enabling the file roll over option, Once the trn file reached limit which we set, automatically one more file will
created. We don’t know how much size the trace file. That’s why we are enabling the file roll over. Keep maximum size
starts from 50 MB.

Step 4 : File extension should be “.trc”. Click save.


Step 5 : Profiler is dangerous tool. why because, It took more resources of the system like CPU, MEMORY etc. It may
lead slow down the sql server. That’s why, we have to run profiler for short time only.

To control this, we have to enable trace stop time. Here, we have to give the minutes to run the profiler. Its helps to
stop profiler after that time period automatically.

Step 6 : Go to event tab, Tick the required,

Step 7 : select the Column filters option in events selection, select database name , Click like, Enter the database name
, click ok. Here if we wont choose the database, profiler trace the queries of all the databases and took more CPU. It
lead to slow down the server.
Step 8 : Click Run. Now it will starts capturing the queries. It wont trace already executed queries. It will trace after
initiating the profiler, what ever queries runs.

If already indexes are there in the table, delete the indexes. Otherwise DTA wont recommend the indexes.

Step 9 : In SSMS, go to tools, select database engine tuning advisor.

Step 10 : Connect to the instance.

Step 11 : Enter the session name, Select the work load and choose the type of output, We have saved the profiler trace
in file format. So, choose the file option, give the path of “.trc” file which we saved earlier. Choose the database, select
the table ,
Step 12 : Click on start analysis.

Step 13 : now it will show the index recommendations and it will show the improvement of query performance if we
create the indexes as per DTA recommendation.

Step 14 : Go to definition column. Here we can see DTA suggested Clustered index on ID column and remaining two
columns non clustered index.
Step 15 : Put the cursor, and copy the script and execute on the sql server. Now index will be created.

Coy and execute for the remaining recommendations also.

119. How to capture the deadlocks by using the profiler?

Ans. Open Profiler, Select the template “TSQL Locks” , select the all the locks related to dead locks in events selection.

120. What is fragmentation?

Ans. When we create a fresh index, data will be organized in order. After performing DML in the data, data will scatter
and order will be gone.

In the below example , if we see.

When fresh index created, data placed in order and took 18 pages. After the DML queries applied on the data, Data
scattered and pages not in order. Now, Query took long time to execute even index is there because of DML queries
performed.
Storing data non uniformly inside the disk is called fragmentation. Simply, Data stored not in order is called
fragmentation. Because of fragmentation , query runs slowly. Always we have to reduce the fragmentation.

Fragmentation occurs when we perform DML operations on the data.

There are 2 types of fragmentation,

a. Internal Fragmentation : if the data is not in uniform inside a page is called internal fragmentation.

b. External Fragmentation : if the pages are not in uniform inside a extent is called External Fragmentation.

121. How to identify and remove the


fragmentation?

Ans. Fragmentation can be identified in two ways,

One is “ DBCC SHOWCONTIG”

Second is
“DM_DB_INDEX_PHYSICALSTATS” (DMV)
To clear the Fragmentation, We have 2 options,

a. Rebuild Index : It will drop the existed index and create the new index. Whenever new index created,
automatically data will places in order. Fragmentation will be eliminated.

b. Reorg Index :it wont drop any index, It will rearrange the data internally . Fragmentation will be controlled.

Rebuild is the best option .

Below are the steps to eliminate Fragmentation,

Select & expand the database, Expand tables, select the table and expand the table, Expand indexes, right click index ,
Choose the rebuild or reorganize.

Or

We can do the above process to eliminate the fragmentation for one or two tables like that. To do all the tables , it will
take long time. So, We use maintenance plan to eliminate the fragmentation of the all the tables.

Creating maintenance plan:

Below are the steps,

Step 1 : Select new maintenance plan, Drag the Rebuild or Reorg index task to the empty space.
Step 2 : Select the database, Ignore the database where state is not online, Click ok.

Step 3 : go to optimize index , Choose the fragmentation percentage and page count, Click ok.

Step 4 : Schedule the maintenance plan and save the maintenance plan.

Step 5 : maintenance plan will be created to eliminate fragmentation as per schedule.

118. If Temp DB is full, How to solve the issue?

Ans. We have to shrink the TEMP DB.


120. What is Clustering?

Ans. Clustering is a instance level high availability. Instance level means, logins, db, jobs and everything will move from
one server to another server in case any issue with the windows server.

In clustering, we called windows servers as Nodes.

Cluster storage:

For Cluster configuration, we required shared storage. That is Storage area network(SAN).

In cluster, When node 1 is down, The sql server will failover from node1 to node2. When sql server moves , the
associate drives(data and log bkp) will be also failover from node 1 to node2.
We don’t keep any data files and log files in the C: Drive . why because it contains windows files. So, we configure the
sql server in the other drives except C drive.

One more imp thing is, We should not keep same drives in the both the nodes, Why because if the same drives already
created in the node2 , Failover not possible. Already same drives exists in the node 2.

We have to take unique drive letters while doing the Clustering. If Node 1 has the D & E drives used for Clustering then
in the NODE 2 , there should not be any drives with the same drives. Always take unique drive letters for each sql
server.

Types of Clustering :

There are 2 types

a. Active – Active Cluster : Each Node contains a different sql servers and each node is capable of maintain 2
sql servers. Simply, Both the Nodes having the SQL Server. Here we called Node 1 as Active Node and Node 2
also called as Active node. Here, Each server should be capable of maintain the 2 servers.

Active means SQL Server available in the windows server.

For example,

In Node 1, Flipkart SQL Server is running.

In Node 2, Amazon SQL Server is running.

When Node1 Windows server is down, Flipkart SQL


Server will failover to NODE2 windows server. Now, Both
the Flipkart and Amazon sql server running in the same
NODE2 Windows server.
b. Active – Passive Cluster : Only one Node has the SQL Server and another NODE don’t have any SQL Server.
The Node, which has SQL Server is called ACTIVE Node. The Node, Which don’t have the sql server called as Passive
Node. Passive node is waiting for the failover of the active node.

Passive Means SQL server not available in the Windows server.

How Cluster Works: Cluster works through heart beat process. A signal will send from one server to another server to
verify the NODE is LIVE or not. Heart beat helps to find out whether the other nodes are alive or not.

Heart beat setup will be done by using private network.

There are 2 types of heart beats, LOOKS ALIVE & IS ALIVE.

a. LOOKS ALIVE : It’s a normal check , which runs for every 5 seconds.

b. IS ALIVE : it’s a deeper check , Which runs for every 60 seconds. It will send a command “select
@@Servername” to know exactly the server is down or not.

When there is a fail over in clustering, SQL Server will be in stopped state for 2 to 3 minutes.

When any of the reason the heart beat of the SQL Server is not working. Then Heart beat will do 2 checks.
1st it will send LOOKS ALIVE check – If receive back the signal from the server, heart beat will continue. If there is no
signal again, then it will send IS ALIVE Check. IS ALIVE Check sends the Command signal to the server and runs for 60
Sec. If the receives the signal back, heart beat will continue. If there is no signal in this check also, SQL SERVER will fail
over to another NODE.

Why 2 checks is , Some times due to network issues also signal wont come. That’s why, SQL SERVER cross check once
again with the LOOKS ALIVE and IS ALIVE. Then only sql server will failover to another windows server.

The total time to failover of a SQL Server is around 2 to 3 minutes in clustering. At this stage, SQL Server is in stopped
state.

Types of network :

There are 2 types of networks,

a. Private Network : used for Internal communication. Acts as a heart beat. To send the signals b/w the servers.

b. Public Network : used for External communication.(users and applications).

Every windows server has one public and one private network.

Virtual Server name or network name : By using virtual server name, the application will connect where ever the sql
server is running. We don’t need to change the connection string with network name whenever the failover happens.

Simply if SQL Server is failover from node 1 to node 2 , We need to ask application team to change the connections
from node 1 to node 2. Automatically with the help of Virtual server name, Connection string also changed to Node 2.

After automatic failover also, Application connection string also automatically changed to where ever sql server is
running.
Adding Binaries : All the SQL Server installation related files are called binaries. Binaries are files, which helps to run
the SQL Server.

In ACTIVE Passive Cluster, There is no sql server in the NODE2. After the failover to NODE2, To run the SQL Server –
binaries are required.

In ACTIVE ACTIVE Cluster , There is already a SQL Server installed and used by some other instance. After the failover
from NODE1 to NODE 2- SQL Servers because already a SQL Server installed in NODE 2.

By using the “ADD NODE” option, we can get the binary files of SQL Server from NODE1 TO NODE2.

If we have installed the SQL Server NODE1, In node 2 we have to add binaries by using ADD NODE.

In Node 3 We have to add binaries by using ADD NODE.

How many IP’s required for Cluster Configuration ?

All the SQL Servers in the Clustering connected to Windows Cluster only.

For 2 Node Clustering, We need 7 IP’s to configure ACTIVE – ACTIVE Clustering

We need 6 IP’s to configure ACTIVE – PASSIVE Clustering

If 3 node clustering, 8 IP’s – A-A Clustering and 7 IP’S A-P Clustering.

To remember the how many IP’s, use the formula – 2n+2 for Active passive clustering

Use the formula – 2n+3 for Active - Active clustering

Don’t tell this formula in interview. Its just to remember only.


QUORUM : IT contains QUORUM.LOG file , which contains all cluster configuration and will decide the sql server from
one server to another server by using voting process. Which node gets the highest votes, SQL server failover to the
highest voting node. Simply, QUORUM decides to which node sql server should failover.

Installation :

How to open Failover cluster Manager?

RUN , CLUADMIN.MSG

121. How to setup 2 node SQL Server Clustering?

Ans. SQL Server clustering installation also same as Stand alone installation only. Only the few changes will be there.

Step 1 : First Windows team will setup windows server failover clustering. After that we have to start.
Step 2 : Open the SQL Server setup file as administrator, Go to Installation Tab, Select New SQL Server failover
installation.

Step 3 : 1st difference – In the Instance configuration Setup page, We have to give SQL Server network name, Provide
the Instance name . Here SQL Server network name acts as a computer name to login in to the sql server.

For example, To login in to a stand alone instance- user name is Computer name\Instance name. In the same way to
login in to the Cluster SQL Server is “SQL Server network name\Instance name”.

Step 4 : 2nd Difference – Choose the resource group. Resource group contains all the resources of the SQL Server.

Step 5 : 3rd difference – choose the eligible drives, where we store data files, log files , backup& tempdb. We cant store
any data on the QUORUM drive.
Step 6 : 4th difference : Now we have to IP address , which will be provided by network team. No need to select DHCP.

Step 7 : 5th difference – Choose the service


account and give password of the service
account. Always startup type should be manual in
the SQL Server cluster. We don’t get option also
to change automatic.
Step 8 : 6th Difference – In the database configuration page, Go to data directories, Choose the drives where we want
to store data, log, backup files.

In the same page , go to TEMPDB tab , Choose the path where we want to store TEMPDB files.

Temp DB is separate configuration has been implemented in the sql server installation from 2017 onwards.

For performance wise, Multiple data files recommended for TEMP DB. Based in the Cores of the PC, Number of temp
db files will be recommended. Max temp db files can be 8 files only.

Step 9 : That’s it. Install.


Step 10 : Now we have to perform ADD Node in the NODE 2 server.

Step 11 : Go to NODE 2 server, Open SQL Server setup file, Run as administrator, Choose the option “ADD Node to a
SQL Server failover cluster”

Step 12 : Choose the SQL Server instance name

Step 13 : Tick the IP Address,


Step 14 : Enter the password of service account

Step 15 : Install.

122. How to Manual failover the cluster?

Ans.

Step 1 : open RUN command on any of the NODE, Type the command “CLUADMIN.MSG”

Step 2 : Go to roles, There we can see SQL Server cluster status.

Step 3 :Right click on the server , Choose the move option, select Node option,
Step 4 : Select the node , which we want to failover. Click ok.

Step 5 : Now all the resource drives will move to NODE 2 and then SQL Server will come online.

Step 6 : Quorum drive wont move to Node 2. It will be in the NODE 1 only. If disaster happens , then automatic failover
automatic failover happens. That time Quorum also moved to NODE2. Why because, Node1 server is fully down.

123. Where to check the cluster related errors?

Ans. Few errors captured in Cluster events and few errors captured in Information details.

124. what are types of owners in Cluster?

Ans. There are 2 types ,

a. Preferred owner : Which node shows first in the list, That server acts as a owner of the SQL Server.
To change the preferred owner, simply select the node and click up and apply.

b. Possible owner : At the time failover, what are the possible nodes available. Those are possible owners.

If we not tick the nodes in this tab, Failover not possible. Because there is not possible node.
125. How to connect SQL Server Cluster Instance?

Ans. Give the “SQL Server network name\Instance name”. Both the names we can get in the Cluster manager.
126. how to patch a cluster setup?

Ans. First we have to check whether failover is working or not.

If its working fine. Then, Patch the passive Node first.

After successful patching, failover the server.

Do the patching for the remaining nodes.

127. how to check an instance is Cluster instance or not?

Ans. Right clock on the server, go to properties,

In the general tab, Is Clustered is True then instance is a clustered.


128. How to shrink a log file on the real time environments?

Ans. Normally, When any log file size of the database is reached 90%. Then we will shrink the log file of the database.

The max log file size 2 TB only.

By using Disk level alerts, we will come to know , when there is disk space issues.

If we got the alert in the outlook, that log file drive is going to full. Then we have to take below steps,

Step 1 : Login in to the windows server.

Step 2 : Check that Logfile drive is really going to full or not in the my computer.

Step 3 : Login in to SQL Server, Type the command “dbcc sqlperf(logspace)”. This command shows how many log files
are there in the sql server and what is the size of the log file.

In the screenshot, sales database log file occupied


5999MB = 6 GB. Now we will shrink the log file of sales
database.

Step 4 : Now we have to check why log file is growing and not reusable. To know that, we have to find the state of the
log file. There are different states,

Mainly are a. Nothing

b. Log backup

c. Active backup or restore

d. active transaction

e. availability replica

f. Check point

g. oldest page
Step 4 : To know the state of the log file use the query “ select name, log_reuse_wait_desc from sys.databases”

if the state of the Log file is ACTIVE_TRANSACTION ,


we have to wait till state to be changed to NOTHING.
State of log file should be “NOTHING”. Then only we
have to shrink the log file.

If the state is showing as “LOG BACKUP”, Then we


have to take log up of the database and re run the
same query , the state will be changed to NOTHING.
Even some times, after taking the log backup also
state wont be changed. So, until the state changed to
nothing, we have to take log backups again and again.
Here one more case, if the log backup file size is 2 TB
and we don’t have space in any of the drives to take
backup. That we can use nul backup. Nul only not null.

“ backup log sales to disk=’nul’ ”. Here backup wont be


stores any where. But our requirement full filled. State
of the log file will be changed to NOTHING.

If the state of the log file is “ACTIVE BACKUP or RESORE”. Then we have to wait to change the status to nothing.

If the state is “OLDEST PAGE” , We have to run the CHECK POINT on the particular database. Then state will be
changed to NOTHING.

Step 5 : Right click on the database , go to tasks, Select shrink , Choose files. Never select the database to shrink.
Always we have to shrink only log file not the data file. If we shrink the data file, fragmentation will be created. Which
leads to performance issue. There is a another way for data file shrink.

Step 6 : Choose the file type as LOG, Cross check the


Location & File name , Select the Reorganize pages
before releasing unused space. In the organization ,,
Shrink file size is 512 MB or 1024 MB. Normally we do
shrinking of log file , which has more than 5 GB.

In the right screenshot, Log file size is 6000 MB. After


clicking ok , The size will changed to what ever size we
kept . In the screenshot we kept 1024 MB. Now log file
size will be shrink from 6000 MB to 1000 MB.

End of the process.


129. What is ALWAYS ON?

Ans. Always on introduced from 2012 version onwards. ALWAYS ON is called as AOAG(ALWAYS ON AVAILABILITY
GROUP). ALWAYS ON is a Stand alone instance. No need to instal cluster instance. But, we need Windows clustering to
perform always on. ALWAYS ON is a advanced version of MIRRORING. In mirroring , we have to configure mirroring for
each database for high availability. But, in ALWAYS ON , HIGH AVAILABILITY Group will be created. Simply, adding the
databases to the group will be converted to HADR. ALWAYS ON also works with help of END POINTS only like
Mirroring. Same synchronous and asynchronous modes available in ALWAYS ON.

Mirroring is a database level high availability, where ALWAYS ON is group level high availability.

Once we create the AG(availability group), we can add the other data bases also the group for high availability.

In ALWAYS ON, we called primary server as Primary Replica and secondary server called as Secondary Replica.
Basically, servers called as Replica in always on.

In Mirroring , we can’t read the data in the secondary server. Where as in always on, we can read the data in the
secondary replica. Like select , back up queries.

Always ON helps to balance the Load of the sql server. For example, Always on applies the insert or update commands
on the primary replica and select and backup commands will run the secondary replica. It will reduce the load on the
same server. These load balance done by the Listener in the always on. Listener route the traffic between the servers.

Lister route the traffic based on the customer requirement.

When any of the database is offline in the always on group. Entire Group will be failover to secondary server.

We need use shared storage for ALWAYS ON. Only for SQL Server Clustering , we use shared storage.

In Always on Application connected to the listener, Whenever the failover happens connection strings of application
also will be changed to active replica automatically with the help of listener.

In mirroring, we have to inform application team to change connection string after the failover.

Listener do 2 things; One is Traffic or load balance on the replicas and Change the connection strings automatically
after the failover to the application. Listener knows which one primary replica and which one secondary replica.

We can configure always on with out listener but automatic failover not possible.
130. What are the prerequisites to configure always on?

Ans.

a. Windows level cluster setup

b. IP address

c. standalone sql server (Version should be 2012 or more)

d. We have to enable the always on feature in configuration manager.

e. database should be in FULL recovery mode.

f. Service account sysadmin permissions.

f. Take the backup of primary replica database and restore it in secondary replica with NO Recovery.

131. What are the steps to configure always on?

Ans. Below are the steps,

a. Windows team will install the cluster setup.

b. Install the Standalone sql server on the replicas(Startup type automatic only)

c. Enable the Always on feature in the configuration manager for all the replicas.

d. Right click on instance, go to properties, select always on high availability tab, Tick the “Enable Always on Availability
group” , Click ok. Do the same process for all the replicas.

e. Keep the database recovery model to FULL

f. Take the database backup in the primary replica and restore it on the secondary replica with no recovery.
g. On the primary replica, select always on high
availability, right click and select new availability group
wizard,

h. Give availability group name , choose the cluster type


“Windows level failover cluster”

i. Now it will show the all the databases of primary replica, choose the databases and it should meet the prerequisites.

j. Specify replicas window- This is the main window to setup always on.
Replicas Tab: Primary replica instance already available. Now add the secondary replica by using add option, Connect
to sql server, Click Connect. Tick the automatic failover for all the replicas, choose the availability mode based on
requirement. If automatic failover, synchronous mode like that.

Choose the readable secondary “Yes” for all the replicas. Then only read operations can be performed on the
secondary replica.

In 2012 sql server, we can add 4 secondary replicas in AG.

In 2016 sql server , we can add 6 secondary replicas in AG.

In 2017 & 2019 server, We can add 8 Secondary replicas in AG.

Added the secondary replica and ticked the automatic failover.

Changed readable to yes.


k. END POINTS TAB : Here we have to give end points port number. Default port number for mirroring or always on is
5022. If we have already configured mirroring 5022 will be already used. So here we have to use 5023. If 5023 also
used for some other configuration, we can choose 5023. At this page , by default 5022 will come. We have to change
the port number manually in the end point url and port number column.

l. backup preferences tab :

There are 4 options :

A. Prefer Secondary : Secondary replica will be used for backup. If secondary replica not available,
Automatically backup will be taken from primary replica.

B. Secondary only : Backup will run only


from the secondary replica.

C. Primary : backup will run only from the


Primary Replica.

D. Any Replica : backups run from any


replica based on the AG. By using Priority
percentage or else ticking the Exclude replica
option in the below ,we can exclude the replica
for backup queries. Mostly don’t use the Exclude
replica option. When we did the failover, backup
job may stop because of excluded the replica for
the backup.

In the organization, mostly we prefer SECONDARY


ONLY OPTION for backup.
j. Listener Tab: Here if you want automatic failover, we have to create availability group listener. Even if we wont
create the listener at this step, we can create after the AG setup also.

Give the Lister name and port number.

If you have selected the default instance as Primary replica then give the port number 1433.

If it’s a named instance, check the port number of instance and then enter the same port number.

In the organization , After the SQL Server named instance installation, we will change the port numbers. There are two
types of ports Static & Dynamic ports. Normally after installation a dynamic port will be allocated to sql server. In the
organization, as a security precaution , they will change the port number manually. After changing the port number ,
we have to request network team to open the ports.

Network mode keep it as Static IP address, Click add, give the IP address
k. Read only Routing Tab : Not explained. Feature from 2016 version onwards.

l. Select data synchronization page : This is a initialization setup page. Choose the join only option. Why because we
have already initialized the database.
M. Click Finish.

You might also like