Locked lesson.
About this lesson
You will learn how to backup a database and how to restore a backup
Quick reference
Backing Up & Restoring a Database
Let's backup and restore our database.
When to use
You should always backup your database.
Instructions
Backing up and restoring a database is a breeze with SSMS.
Right click your database in the object explorer and select "Tasks" and then "Backup".
Save your backup file with a .bak file extension.
To restore your backup, Right click the Databases folder in object explorer, and select "Restore Database".
Hints & tips
- To Save a Backup: Right click your database in the object explorer and select "Tasks" and then "Backup".
- Save the file with a .bak file extension.
- To Restore a Backup: Right click the Databases folder in object explorer, and select "Restore Database".
- 00:05 I've added a few more rows to our database just to flush things out a little bit.
- 00:08 In this video now, I wanna talk about backing up our database,
- 00:12 as well as restoring our database.
- 00:13 So it's so important to back up your stuff here.
- 00:16 You're always gonna want to back up your databases.
- 00:18 Right now we have, what, six rows of information?
- 00:21 It's not a huge deal if we back this up or not, but in real life,
- 00:24 you could have thousands, tens of thousands, millions of rows of data, and
- 00:28 you're always gonna want to back that up.
- 00:30 Now, you're going to want to back up your stuff off-site.
- 00:32 Don't keep your backups on your computer obviously cuz if your computer goes down,
- 00:37 everything is lost.
- 00:37 So it's always a good idea to keep your stuff off-site but in this video I'm just
- 00:41 gonna show you the actual mechanics of making a backup and restoring a backup.
- 00:45 So it's very easy to do that you'll just come over here, click on your database.
- 00:49 Now, we wanna back up our customer database.
- 00:51 So we right-click here and click tasks.
- 00:54 And then scroll down, and it's just backup.
- 00:57 Very simple.
- 00:57 So here's our database, customer.
- 01:01 And we want a full backup.
- 01:03 We don't want a differential and we don't want a transaction log.
- 01:05 We want the full thing.
- 01:07 And the rest of these are defaults so it's gonna give you a whole big long line of
- 01:13 where it wants to save this file, but you click remove and
- 01:18 then add and you can tell it exactly where you want to save your backup.
- 01:22 So I'm just gonna click on the C drive and I've created a directory
- 01:27 called backups, it doesn't really matter where you save it, and then just name it.
- 01:32 I'm gonna call this customers.bak.
- 01:34 And the bak is the file extension type that these backup files get saved as.
- 01:41 It's just the format that they use.
- 01:43 So you wanna definitely put .bak on there.
- 01:46 If you leave that off, it's gonna give you an error.
- 01:48 Go ahead and click OK.
- 01:49 Click OK again.
- 01:51 So looking through this, I think we're good to go.
- 01:54 We can just click OK now.
- 01:57 We get this message that backup of database customer completed successfully.
- 02:00 So, click OK.
- 02:02 I'm just going to pull up my Thing here and
- 02:06 look at my C drive, backups and sure enough here it is, customers.bak.
- 02:11 So now, I can come over here and right click on Customers and click Delete
- 02:18 and delete this thing, and then OK and so it's disappeared.
- 02:22 If we hit refresh, it is definitely gone.
- 02:25 So in order to restore this thing now that we've accidentally deleted it, no,
- 02:29 how do we bring it back?
- 02:31 No problem at all, let's just right-click on this,
- 02:34 and Restore Database, right here on top.
- 02:38 So we get this restore database screen and if we click on device and
- 02:43 then click this little button here, and then click add,
- 02:47 we can navigate around and find our file that we saved.
- 02:50 Saved it in C:/Backup.
- 02:52 There it is, customers.bak.
- 02:54 Click OK.
- 02:56 Click OK.
- 02:58 And so now here it's listed.
- 03:00 That's all the good stuff.
- 03:02 We can scroll through there and look at that if you want, click OK.
- 03:06 Database Customer restored successfully.
- 03:08 So now if we look back here, we don't even have to hit the Refresh button but
- 03:12 I'll do it anyway.
- 03:13 Here we have our customer database.
- 03:15 If we expand the tables, there's our current Customers table,
- 03:19 I'll right-click this and edit top 200 rows, boom.
- 03:22 I see all of our nice information.
- 03:24 There's our six rows of information that we had before, and
- 03:27 everything has been successfully backed up.
- 03:29 So, pretty simple, pretty straightforward.
- 03:31 You just back up and restore, just like that.
- 03:33 A few clicks, no big deal at all.
- 03:35 So, that's all for this section.
- 03:37 We've installed Microsoft SQL Server 2016.
- 03:39 We've got it up and running.
- 03:41 We've created databases.
- 03:42 We've created tables.
- 03:43 We've added data.
- 03:44 In the next section, we're going to start talking about actual SQL stuff and
- 03:47 we're going to see how to programatically pull stuff out of our database and
- 03:52 all that good stuff.
- 03:52 So, in the next video we will look specifically at the select statement.
Lesson notes are only available for subscribers.