How to find SQL Server Port Number using SQL Server Management Studio - SQL Server DBA Tutorial

This video illustrates following:

1- How to find SQL Server Port number using SQL Server Management Studio (SSMS)
2- How to find Default and named instances of SQL Server Port using Regedit
3- How to read values from registry related to SQL Server
4- How to find SQL Server Port Number using T-SQL Script

Script to get Port Number for SQL Server Instance

DECLARE @PortNumber VARCHAR(10), @KeyValue VARCHAR(100)
IF CHARINDEX('\',@@SERVERNAME,0) <>0
BEGIN
SET @KeyValue = 'SOFTWARE\MICROSOFT\Microsoft SQL Server\'+@@SERVICENAME+'\MSSQLServer\Supersocketnetlib\TCP'
END
ELSE
BEGIN
SET @keyValue = 'SOFTWARE\MICROSOFT\MSSQLServer\MSSQLServer \Supersocketnetlib\TCP'
END
--How to read Registry in T-SQL Terms - ROOTKEY, KEY, VALUENAME,VALUE 
EXEC master..xp_regread 'HKEY_LOCAL_MACHINE',@KeyValue,'Tcpport',@value=@PortNumber OUTPUT


SELECT 'SQLSERVER_NAME: '+@@SERVERNAME + ' : SQL SERVER Port Number:'+CONVERT(VARCHAR(10),
@PortNumber)


Get SQL Server Port Number using SQL Server Management Studio - SQL Server DBA Tutorial