Create SQL AlwaysOn Availability Group Using Transact SQL
This example uses TransactSQL statement to make an AlwaysOn availability group named INFOTECHGUYZ for two user databases, INFOTECHGUYZDb1 and INFOTECHGUYZDb2, which reside on the local computer node. A local stand-alone server instance, HADR_INSTANCE, is specified first. This instance will host the initial primary availability replica. Another stand-alone server instance, also named HADR_INSTANCE, is specified to host the initial secondary replica. Each database mirroring endpoint uses the fully-qualified domain name of the host computer, computer_name.infotechguyz.com, and port 7022. This example configures both availability replicas so that whichever replica is performing the secondary role allows all connections for read access to its secondary databases.
CREATE AVAILABILITY GROUP INFOTECHGUYZ
FOR
DATABASE INFOTECHGUYZDb1, INFOTECHGUYZDb2
REPLICA ON
'COMPUTER01\HADR_INSTANCE' WITH
(
ENDPOINT_URL = 'TCP://aCOMPUTER01.infotechguyz.com:7022',
PRIMARY_ROLE = (ALLOW_CONNECTIONS = ALL),
SECONDARY_ROLE (ALLOW_CONNECTIONS = ALL)
),
'COMPUTER02\HADR_INSTANCE' WITH
(
ENDPOINT_URL = 'TCP://aCOMPUTER02.infotechguyz.com:7022',
PRIMARY_ROLE = (ALLOW_CONNECTIONS = ALL),
SECONDARY_ROLE (ALLOW_CONNECTIONS = ALL)
);
GO
