New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Restoring databases

From: SQL Server 2008 Essential Training

Video: Restoring databases

One of the reasons I like to get into the habit of backing up regularly even when I'm just working with sample databases on a development server is that it's way too easy to run a little bit a code that maybe does a little bit more than you expected. So I'm pasting in a few delete statements here. This is not the kind of code you want to execute a lot. Well this is going to do with the no WHERE statements is it's going to go through and delete everything in all of those tables. So say this accidentally happened yesterday, a few hours ago, a few seconds ago.

Restoring databases

One of the reasons I like to get into the habit of backing up regularly even when I'm just working with sample databases on a development server is that it's way too easy to run a little bit a code that maybe does a little bit more than you expected. So I'm pasting in a few delete statements here. This is not the kind of code you want to execute a lot. Well this is going to do with the no WHERE statements is it's going to go through and delete everything in all of those tables. So say this accidentally happened yesterday, a few hours ago, a few seconds ago.

And I'm now in the problem that when I go and look at my Customer table, for example, I have nothing whatsoever and this is not what I want. Well luckily I was doing regular backups so I can restore these. I'm going to do this from SQL Server Management Studio, though you can do it from the SQL command line. I'll right-click one of the databases again it doesn't matter. Even if the database wasn't showing up, you can still pick any of them. Go into Tasks and then Restore. We're going to restore the database.

And again it gives you the drop-down. Is this the one that you want? Yes it is. So a point in time most recent possibly? Yeah absolutely. If you had a specific date and times in a long chain of backups, you can pick it from a particular place. We don't need to here. And because I've been using SQL Server management studio to do my backups, it's taken a look and says okay I have the available files. I know the backup set. I'm ready to go. What else would you like to do? I do have a few options. I'm going to leave everything as is. There are some options you might want to look at if your situation is a bit more unusual, because there's what's called a recovery state.

What state do we want the database to be in when it brings up? Perhaps you're trying to recover a state of the database where you're just interested in getting it as accurate as possible, but as far as you're concerned it could be in read only mode. Well that's not usual. I want to have this database ready to go and ready to use. I'm going to leave all the options there. I'm going to click OK. It's throwing me up an error that exclusive access could not be obtained because the database is in use. Well we've got a couple of things we can try there.

It's probably just a little bit more concerned with the fact that I only just did those DELETEs and it's hanging on to some locks here, so I'm just going to reconnect to the instance. Go back in and try to select to restore the database again, leaving all the default options, and then click OK. And this time we're looking good. Of course, the proof is can we go back into that database and find to say the customer information? And yes, we can.

Now similar to working with your incremental and your full backups, if you are working with a restore, that can be scripted if you need to. Hopefully you are not having to do a restore of your database often enough that you actually need to have a permanent script file for doing it. And certainly if your database is in a more complex situation, if you're doing not just the regular full and differential backups, but you have split your backups into the more granular pieces of file groups and transaction logs, you are going to want to take a little bit more care than just the quick way that we've done it.

But certainly when working with a development server, like we're doing right now, this should be a perfectly and acceptable way to do both your backups and your restores.

Show transcript

This video is part of

Image for SQL Server 2008 Essential Training
SQL Server 2008 Essential Training

74 video lessons · 35804 viewers

Simon Allardice
Author

 
Expand all | Collapse all
  1. 2m 21s
    1. Welcome
      1m 19s
    2. Using the exercise files
      1m 2s
  2. 17m 58s
    1. SQL Server core concepts
      9m 4s
    2. SQL Server editions
      3m 8s
    3. Applications included with SQL Server
      5m 46s
  3. 26m 1s
    1. Preparing for installation
      3m 44s
    2. Creating service accounts
      2m 33s
    3. Installing SQL Server
      11m 42s
    4. Post-installation checks
      3m 9s
    5. Installing sample databases
      4m 53s
  4. 13m 35s
    1. Introduction to SQL Server Management Studio
      8m 7s
    2. Introduction to SQL Server Books Online
      3m 6s
    3. SQL Server system databases
      2m 22s
  5. 1h 26m
    1. Planning your database
      9m 39s
    2. Creating a SQL Server database
      4m 7s
    3. Creating tables
      7m 51s
    4. Data types in SQL Server
      12m 25s
    5. Defining keys
      8m 9s
    6. Creating default values
      4m 39s
    7. Creating check constraints
      2m 25s
    8. Creating unique constraints
      4m 34s
    9. Introduction to relationships and foreign keys
      9m 51s
    10. Creating relationships in SQL Server Management Studio
      8m 14s
    11. Database normalization
      11m 47s
    12. Creating computed columns
      3m 10s
  6. 23m 11s
    1. Using the SQL Server Import and Export Wizard
      3m 58s
    2. Importing Excel files into SQL Server
      6m 11s
    3. Importing CSV files into SQL Server
      5m 27s
    4. Importing Access databases into SQL Server
      7m 35s
  7. 55m 29s
    1. Introduction to Transact-SQL
      3m 43s
    2. Using SELECT statements
      7m 16s
    3. Changing the default database
      2m 21s
    4. Creating conditions in SQL
      8m 10s
    5. Sorting your output
      3m 23s
    6. Using aggregate functions
      7m 12s
    7. Finding unique values
      2m 14s
    8. Joining multiple tables together
      8m 0s
    9. Using subqueries
      9m 33s
    10. Viewing execution plans
      3m 37s
  8. 19m 36s
    1. Writing INSERT statements
      5m 47s
    2. Writing UPDATE statements
      4m 38s
    3. Writing DELETE statements
      2m 54s
    4. Using the OUTPUT clause to return inserted keys and GUIDs
      6m 17s
  9. 32m 52s
    1. Introduction to SQL functions
      6m 26s
    2. Using SQL configuration functions
      2m 14s
    3. Using string functions
      7m 26s
    4. Using date functions
      6m 27s
    5. Creating user-defined functions
      10m 19s
  10. 28m 46s
    1. Introduction to stored procedures
      4m 23s
    2. Creating stored procedures
      11m 23s
    3. Introducing transactions
      4m 23s
    4. Creating transactions
      8m 37s
  11. 16m 39s
    1. Understanding and creating indexes
      6m 32s
    2. Monitoring and rebuilding indexes
      6m 0s
    3. Monitoring database size and integrity
      4m 7s
  12. 11m 41s
    1. Creating backups
      4m 21s
    2. Creating differential backups and using backup compression
      3m 40s
    3. Restoring databases
      3m 40s
  13. 17m 40s
    1. Introduction to SQL Server security and permissions
      5m 54s
    2. Adding a Windows user to the database
      5m 7s
    3. Creating SQL Server logins and switching authentication modes
      6m 39s
  14. 36m 41s
    1. Introduction to SQL Server Reporting Services
      2m 52s
    2. Connecting to the Report Manager
      4m 29s
    3. Using Report Builder
      12m 4s
    4. Formatting values in reports
      4m 17s
    5. Adding indicators to reports
      5m 11s
    6. Adding charts to reports
      3m 54s
    7. Working with report security
      3m 54s
  15. 24m 41s
    1. Introduction to SQL Server Integration Services (SSIS)
      1m 57s
    2. Using Business Intelligence Development Studio (BIDS)
      6m 59s
    3. Creating and executing a simple SSIS package
      7m 35s
    4. Importing packages into SQL Server Management Studio
      3m 21s
    5. Scheduling jobs with SQL Server Agent
      4m 49s
  16. 31s
    1. Goodbye
      31s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold

Are you sure you want to delete this note?

No

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.