Msg 7940, Level 16, State 1, Line 1
System databases master, model, msdb, and tempdb cannot be detached.
This error message appears when you try to detach one of SQL Server own system databases.
The T-SQL statement can be parsed, but causes the error at runtime.
Error of the Severity level 16 are generated by the user and can be fixed by the SQL Server user. You cannot detach the system databases.
All versions of SQL Server.
EXEC sp_detach_db ‘TempDB’