
The code below will consider a database named AdventureWorksLT2019 and store a backup created on November 16, 2021, at 11: 37 PM. But for this tutorial, the file is named backup1.sql saved in the C:\ata_db folder. Open your favorite text editor, copy/paste the T-SQL content below, and save the file with your preferred name. You are free to follow a different convention, just be aware that you will need to change the commands in the scripts accordingly.ġ.

The suggested convention stores the hour and minutes following the 24-hour layout (e.g., 2300 for 11 pm). So, why not follow a naming convention for your backup files?įor this tutorial, you can adopt the YYYYMMDD_HHMM_DatabaseName.bak convention. Typically, you’d want to identify a backup file at first glance. Now that you have settled on a backup folder, it’s time to build the script. Backing up a Database Following a Naming Convention The chosen path will be shown in the commands throughout this tutorial as C:\ata_db\name_of_your_file. For this tutorial, the folder is named C:\ata_db. Lastly, create a folder to hold all your backups. Restore your database to Microsoft SSMS, in this case, AdventureWorksLT2019.bak.ģ. Open PowerShell as administrator, and run the below command to verify if sqlcmd works on your PowerShell session.Ģ. And these script files perform tasks like backing up your databases.īut before backing up your database, you’ll first have to verify if sqlcmd works and create a backup folder.ġ. sqlcmd is a command-line utility tool that allows you to run SQL script files. T-SQL is a Microsoft-specific extension to the SQL language. In this tutorial, the first method you’ll try is creating a Transact-SQL (T-SQL) script. A Windows 10 machine – This tutorial uses OS Build 19043.1288.This tutorial uses Windows PowerShell 5.1, but later versions will also work.


