MsSQL DBA Notes
MsSQL DBA Notes
Ans. SQL Server is a Microsoft product. We can call it as Microsoft SQL Server or MS SQL Server.
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.”
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.
Tier 2 – Application
Ans. Installing and Maintaining the SQL Servers. Creating Logins & giving permissions.
Taking Backups & doing restores, database refresh tasks, backup failures.
Configuring high availabilities. Fixing and troubleshooting the issues. Tuning the Sql server.
3.What are the environments in organization?
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.
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.
Ans. I have worked in production and non-production. In non-production, worked in Dev, Stage, QA, UAT & TEST.
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 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. 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.
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.
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
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.
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.
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.
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,
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.
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.
15.What are the main components or features or applications or ADD ONs in 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.
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.
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.
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.
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
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.
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.
m. Service Accounts –
Local service
Local System –
Very IMP
software runs
under the Local
System. Read,
write operations
happened in this
account.
Network
Service
Next go to data directories and give the location to store the data directories.
Ans.
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. It helps to identify the Syntax & Symantec errors. Short cut is Cntrl+F5.
24. How to select the database while running the query itself.
We can start the instance from the above options, from command prompt type “net start instance name”
Ans.
Ans.
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.
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?
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
Balance size of 8060 bytes used for body. Total 8192 bytes=8 kb = 1 page
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.
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?
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.
a. Implicit Transaction: All the implicit transactions are auto committed. It means without Begin Tran and
Commit
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.
Commit
Ans.
a) right click on database, select the tasks, choose the shrink option, select files like below
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.
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,
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.
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. 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.
d. Select the which server or which instance, you want to patch, click next
g. Update completed screen and make sure all the features in this screen succeeded. If any feature is
failed, Patching is failed.
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.
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.
51. What are the terminologies used in organizations for different types of teams?
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.
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)
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.
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?
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
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
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.
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.
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?
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?
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,
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:
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.
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.
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?
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,
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.
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.
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
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:
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.
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:
i. db_denydatawriter: A member of deny_datawriter, user cant insert, delete, update the data of
a particular database.
Ans. Check point helps to copy all the committed transactions from log file to datafile.
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”
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”
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.
check_expiration=off”
Method 2: If you have a login and user map both login and user by doing AUTOFIX METHOD.
Method 3 : if you want to create a new login and password for the user ,
ZAns. A Lock will be created when any transaction performed on the table .
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.
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.
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.
Now SQL Server keep the lock for particular range i:e; is 1-1000 rows 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.
SP_WHO or SP_WHO2 or
Or
Now we have to kill the blocked the session by using below query,
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.
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.
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,
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.
k. Cold backups : if backup is being taken for once specific database then
75. What are the media options in the backup?
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.
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.
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.
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.
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”
Ans.
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?
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.
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.
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”
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.
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,
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.
g. Click finish.
h. Success message
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
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
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.
Enter the name , choose the type , choose the object , choose the counter , Choose the
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.
Few examples :
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)
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.
Ans. The type of data which users provided to a specific column is called a Data Type.
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:
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.
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.
Ans. We can check what are issues will face before if we do any
migration.
‘Computername\instancename’
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
c. Go to installation tab, Choose the upgrade from a previous version of sql server.
d. Specify the developer edition , 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.
j. Click on upgrade.
k. Upgradation completed.
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)
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.
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.
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.
u. Now we have to change the compatibility of databases manually. By using the query
Ex:
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.
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 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,
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.
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.
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
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
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
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
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.
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 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:
Ans. Fail over means , When primary server is down bringing the secondary server online is called failover.
Step 3 : Check what are the backups pending to restore in the secondary server from primary server
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.
106. How to connect multiple instances of different windows server machines in a single windows server?
Step 3 : GO to SQL Server Services , Start the SQL Server browsing services.
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.
1) High performance mode : In this mode, we don’t have automatic fail over .
112. how to setup Mirroring?
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.
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,
Ans. Right Click on Principal Database, go to tasks, select launch database mirroring
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.
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.
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.
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).
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.
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.
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.
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.
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” .
To see the all the costs of the query, Just put the cursor 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.
Now we can see SQL Server used SEEK process because we created the Index.
For Example, In the below Query PRICE column used after where condition. So, We will create Index on the PRICE
Column.
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.
To avoid this, Now we will create NONClustered index on the Executed column.
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.
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.
Step 1 : Expand the database, Expand tables, Expand the required table, Expand indexes , select non clustered index,
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.
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 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.
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 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 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.
Ans. Open Profiler, Select the template “TSQL Locks” , select the all the locks related to dead locks in events selection.
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.
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.
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.
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.
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.
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.
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.
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 :
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.
For example,
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.
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 :
a. Private Network : used for Internal communication. Acts as a heart beat. To send the signals b/w the servers.
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.
All the SQL Servers in the Clustering connected to Windows Cluster only.
To remember the how many IP’s, use the formula – 2n+2 for Active passive clustering
Installation :
RUN , CLUADMIN.MSG
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.
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 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 15 : Install.
Ans.
Step 1 : open RUN command on any of the NODE, Type the command “CLUADMIN.MSG”
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.
Ans. Few errors captured in Cluster events and few errors captured in Information details.
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. Normally, When any log file size of the database is reached 90%. Then we will shrink the log file of the database.
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 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.
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,
b. Log backup
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 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.
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.
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.
b. IP address
f. Take the backup of primary replica database and restore it in secondary replica with NO Recovery.
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.
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,
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.
A. Prefer Secondary : Secondary replica will be used for backup. If secondary replica not available,
Automatically backup will be taken from primary replica.
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.