Many a times we need to find details about SQL server installation when inheriting a new environment or a setup. One way to figure it out is by reading a registry.
If you have been working on windows since long time you should be aware of registry. Below is a snapshot of details about Microsoft SQL Server contained in Registry. Open RUN command window and type regedit to open up the registry.
Open up registry and navigate to HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\MICROSOFT SQL SERVER\MSSQL12.SQL2014\Setup (for SQL Server 2014). On the left hand pane there are multiple setup configuration option listed. So, to get value of SQLPath option we need to write below T-SQL
DECLARE @Registry_Value VARCHAR(1000) EXECUTE xp_regread 'HKEY_LOCAL_MACHINE', 'SOFTWARE\MICROSOFT\MICROSOFT SQL SERVER\MSSQL12.SQL2014\Setup', 'SQLPath', @Registry_Value OUTPUT SELECT @Registry_Value
The output of the above query is shown below.
The procedure xp_regread is extended undocumented stored procedure to read registry values. The first parameter is the root node, second is the path and the third one the key value to get the value of. Replace the key value ‘SQLPath’ with productcode to get the CD key.
For SQL2005 version the values for 2nd and 3rd parameter are “SOFTWARE\Microsoft\Microsoft SQL Server\80\Registration” and “CD_KEY” respectively.