SQL Server – Restore database from Command Prompt using sqlcmd command

Introduction

Here, I will explain how to restore an SQL Server database from Command Prompt using sqlcmd utility.  We will use RESTORE DATABASE command to restore the database from a backup (.bak) taken using BACKUP DATABASE command. Click here for Backup Database from Command Prompt.

Step 1: Open Command Prompt and type sqlcmd -S localhostSQLServer2014 -U sa , then press enter. Here localhostSQLServer2014 is server nameinstance name and sa is the username.

sqlcmd command

Note : To restore database using Windows Authentication, type sqlcmd -S localhostSQLServer2014 -E and press enter and skip the Step 2

Step 2: Type your password and press enter

SQLCMD Command

Step 3: Type RESTORE DATABASE Galaxy FROM DISK=’D:DataGalaxy.bak’ and press enter. Here we are restoring a full database from a backup.

SQLCMD

Step 4: Type GO and press enter

SQLCMD RESTORE DATABASEFor more information and examples about RESTORE DATABASE command please visit http://msdn.microsoft.com/en-us/library/ms186858.aspx

Leave a Reply

Your email address will not be published. Required fields are marked *