Windows update database error detected

Save this script as a batch file and run as a admin. After that reboot the system and run the windows updates.

@echo off
echo ============================================
echo Resetting Windows Update Components...
echo ============================================

:: Stop services
net stop wuauserv
net stop cryptSvc
net stop bits
net stop msiserver

:: Rename folders
Ren C:\Windows\SoftwareDistribution SoftwareDistribution.old
Ren C:\Windows\System32\catroot2 Catroot2.old

:: Restart services
net start wuauserv
net start cryptSvc
net start bits
net start msiserver

echo ============================================
echo Process Completed Successfully.
echo ============================================
pause

Credits goes here https://www.kapilarya.com/potential-windows-update-database-error-in-windows-10