svg

System administrator info

    mail: srvsysinfo@gmail.com

    Uninstalling SQL Server Using Command Line

    Windows / 30.01.2024

    You can use the built-in Windows Installer tool (msiexec) to remove programs. In order to remove any program installed through the Windows Installer, you need to run the following command:

    msiexec /x {guid}
    Here you must specify the application GUID. To obtain MS SQL Server application GUIDs on Windows, run the command:

    wmic product get Name,IdentifyingNumber
    wmic product get Name,IdentifyingNumber -0 list windows installer guids

    There is a unique GUID for each component of the SQL Server. If you want to remove a specific SQL feature, locate it in the list, and then run the command:

    msiexec /x {2C33F4D4-E9A5-4DE1-ACFE-3A13464E6703}
    Confirm the removal of the SQL Server product feature.

    msiexe uninstall SQL Server by GUID

    In the same way, you will need to remove other components of SQL Server.

    The following PowerShell script gets the GUIDs of all SQL Server components and removes them one by one.

    $SQLVer = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where-Object { $_.DisplayName -match “SQL Server ” } | Select-Object -Property DisplayName, UninstallString
    ForEach ($ver in $SQLVer) {
    If ($ver.UninstallString) {
    $uninst = $ver.UninstallString
    Start-Process cmd -ArgumentList “/c $uninst /quiet /norestart” -NoNewWindow
    }
    You must delete the SQL Server data and registry entries after you uninstall the SQL Server components.

    Note. In my case, the C:\Program Files\Microsoft SQL Server folder size was over 100GB (mostly *.dmp files in the MSSQL15.MSSQLSERVER folder).delete MSSQL15.MSSQLSERVER directory
    Delete the SQL Server directories. You can delete them from Windows Explorer or using the commands:
    rmdir /S /Q “c:\Program Files\Microsoft SQL Server”
    rmdir /S /Q “c:\Program Files (x86)\Microsoft SQL Server”
    rmdir /S /Q “c:\ProgramData\Microsoft\Microsoft SQL Server”
    rmdir /S /Q “%userprofile%\AppData\Roaming\Microsoft\Microsoft SQL Server”
    rmdir /S /Q “%userprofile%\AppData\Local\Microsoft\Microsoft SQL Server”
    Open the Registry Editor and delete the following keys (if they exist):
    HKEY_LOCAL_MACHINE\Software\Microsoft\Microsoft SQL Server
    HKEY_LOCAL_MACHINE\Software\Microsoft\MSSQLServer
    HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\MSSQLServer
    HKEY_CURRENT_USER\Software\Microsoft\Microsoft SQL Server
    Go to the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services key and remove all of the SQL Server services.
    Reboot Windows