@echo off
REM ie. --> detachdb dBname

cls

:detach
set /p dBname="Type in your database name > "
if [%dBname%] EQU [] goto noargs

if NOT exist c:\"program files\microsoft sql server\mssql\data"\%dBname%.mdf goto error
if NOT exist c:\"program files\microsoft sql server\mssql\data"\%dBname%.ldf goto error

echo use master > c:\advantage\~detach.sql
echo go >> c:\advantage\~detach.sql
echo exec sp_detach_db '%dBname%' >> c:\advantage\~detach.sql
echo go >> c:\advantage\~detach.sql

osql -U sa -P advantagesystem -i c:\advantage\~detach.sql
osql -U sa -P "" -i c:\advantage\~detach.sql

del /Q c:\advantage\~detach.sql
exit

:noargs
goto detach

:error
cls
echo %dBname% does not exist
goto detach
