1.Assuming database is backed up earlier either through command
line or SSMS

BACKUPDATABASE Foodmart TODISK=‘C:\Foodmart.bak’

2.While trying to restore using below

RESTOREDATABASE Foodmart FROMDISK=‘C:\Foodmart.bak’

If you are getting below error

Msg 3101,Level 16,State 1, Line 1

Exclusive access could not
be obtained because the databaseisin use.

Msg 3013,Level 16,State 1, Line 1

RESTOREDATABASEis terminating abnormally.

3. To get rid of above error

Set the database in SINGLE_USER mode and forcibly terminate
other connections

ALTERDATABASE Foodmart

SETSINGLE_USERWithROLLBACK IMMEDIATE

4.Then try to restore again

RESTOREDATABASE Foodmart FROMDISK=‘C:\Foodmart.bak’

If restore is Successful then you are done!

But if you are getting below error go to Step 5 else Step 6

Msg 3159,Level 16,State 1, Line 1

The tail of the logfor the database "Foodmart" has not been backed up.
Use BACKUPLOGWITHNORECOVERYtobackup the logif it contains work you do not
want to lose.
Use the WITHREPLACEorWITHSTOPAT clause of the RESTOREstatementto just overwrite the contents of the log.