SQL database Offline or Online

When you are working with the databases to restore or backup you may come across the error:

“Cannot Backup/Restore (especially) when database is in use”

So in order to over come the database status,

Right Click on Database -> New Query:

sp_dboption ‘dbname’,’offline’,’true’ (It will make the database to become offline)

sp_dboption ‘dbname’,’offline’,’false’ (It will bring the database back to online)

(or) simply

Alter Database ‘database name’
set offline

Alter Database ‘database name’
set online