Import Export Backup MSSQL Database

download Import Export Backup MSSQL Database

of 30

Transcript of Import Export Backup MSSQL Database

  • 8/13/2019 Import Export Backup MSSQL Database

    1/30

    Dr. Thomas E. Hicks

    Computer Science Department

    Trinity University

    Purpose

    The purpose of this tutorial is to show how to use Microsoft SQL Server Management Studio Express to (1) import and

    export data to the same instance of the Microsoft SQL Server Express server. The last section of this tutorial shows how

    to attach original database data to alternate servers.

    Previous Tutorials That Might Help You With This Tutorial

    If You Have Difficulty With This Tutorial, You Might Find These Help Prepare You For This Tutorial

    I Recommend That My Students Complete The Tutorials In This Order!

    Tutorial: Microsft SQL Server Express- 2008 Advanced (With Server Management Studio) Express Install

    Tutorial: MSSQL Database Construction With Server Management Studio

    Why Do

    There are a number of reasons that you should back up your databases; three of the more important reasons would be:

    All hard drives will eventually go bad; a current backup will enable you to restore the databases.1.

    When developers are designing new procedures and queries, they will often test those functions on a backup copy

    of the database; once the testing proves to be correct, they can be used on the original database. If the

    procedures or queries are found to be faulty, the original database has not been destroyed.

    2.

    There will be times when you wish to transfer a copy of the database to a second computer system. Exporting

    from the original database system and Importing to the second computer system will enable you to establish the

    second database.

    3.

    There are a number of reasons that you should back up your databases; three of the more important reasons would be:

    The Database

    1] We shall backup the Northwinddatabase on Net1. Note that the Northwind database contains 8 tables.

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    2/30

    2] The Customersdatabase table contains 91 records. We shall open up our copy and make sure that the Customerstable looks similar to that below.

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    3/30

    A Zipped Copy Of Northwind.bak For You To Download

    Northwind.zip

    Export/Backup The Northwind Database

    1] Using the mouse, right-mouse-click on the NorthwindDatabase --> Select Tasks--> Select Back Up... (See Below!)

    2] We are going to do a Full Backup. You can rename the backup, but we are going to leave ours as Northwind-Full

    Database Backup. This is going to create a file, called Northwind.bakin directory. Using the mouse, select/push the OK

    button. (See Below!)

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    4/30

    3] The BackUp takes only seconds to complete. Using the mouse, select/push the OK button. (See Below!)

    4] Take a look in directory C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup- you will see file

    Northwind.bak. (See Below!)

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    5/30

    Delete The Original Northwind Database

    1] Using the mouse, right-mouse-click on the NorthwindDatabase --> Select Delete(See Below!)

    2] Using the mouse, select/push the OKbutton.

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    6/30

    3] Note that the Northwind database is no longer there. (See Below!)

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    7/30

  • 8/13/2019 Import Export Backup MSSQL Database

    8/30

    What To Do If I Have Problems Importing:

    Either DoA] The easiest solution is to copy (right mouse click on file -> Select Copy) the file and paste (right mouse

    click on your backup directory -> Select Paste) it into the backup directory associated with your Microsoft

    SQL Server application.[Note: If you drag the file into that folder with the mouse, it will not have the right

    permissions. A drag file maintains the original file permissions, but a copy file acquires the permissions

    of the host folder.]

    Or

    B] Provide full control of the backup file to the SQLServer2005MSSQLUser

    2] Using the mouse, right-mouse-click on Databases--> Select Restore Database (See Below!)

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    9/30

    3] Name the database Northwind. Select the From Deviceradio button. Select the to identify the backup file. (SeeBelow!)

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    10/30

    4] We need to Add the backup file. Using the mouse, select/push theAddbutton. (See Below!)

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    f 30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    11/30

    5] Locate the backup file in the top window. Using the mouse, select/push the OKbutton. I have selected Northwind.bak

    on C:\ (See Below!)

    6] Using the mouse, select/push the OKbutton. (See Below!)

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    f 30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    12/30

  • 8/13/2019 Import Export Backup MSSQL Database

    13/30

  • 8/13/2019 Import Export Backup MSSQL Database

    14/30

    Import//Restore Northwind.bak To Make A Dupl icate Database Called

    Nortwind2.bak

    1] Suppose we have a copy of our Northwind.bakin directory C:\ (See Below!)

    2] Using the mouse, right-mouse-click on Databases--> Select Restore Database (See Below!)

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    f 30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    15/30

    3] Name the database Northwind2. Select the From Deviceradio button. Select the to identify the backup file.

    (See Below!)

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    f 30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    16/30

    4] We need to Add the backup file. Using the mouse, select/push theAddbutton. (See Below!)

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    f 30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    17/30

    5] Locate the backup file in the top window. Using the mouse, select/push the OKbutton. I have selected Northwind.bak

    on C:\ (See Below!)

    6] Using the mouse, select/push the OKbutton. (See Below!)

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    f 30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    18/30

    7] Check the box beside Northwind-Full Database Backup. Using the mouse, select/push the OKbutton. (See Below!)

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    f 30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    19/30

    8] Using the mouse, select/push the OKbutton. (See Below!)

    9] As you can see below, once again we have a Northwind2database whose Customertable has 91 records. This

    process can be used to make a duplicate copy of the Northwind database on the same SQL/SQLEXPRESS Server. This

    copy might be used to test procedures and queries; it can also be used for development. (See Below!)

    Al ter The Original Northwind Database

    1] Note that I have deleted the OrderDetail and the Orders tables from the Northwind database. I have also reduced the

    91 Customer table records to only 12. (See Below!)

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    f 30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    20/30

    Restore The Northwind Database From Northwind.bak

    1] Suppose we have a copy of our Northwind.bakin directory C:\ (See Below!)

    2] Using the mouse, right-mouse-click on Databases--> Select Restore Database (See Below!)

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    f 30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    21/30

    3] Name the database Northwind. Select the From Deviceradio button. Select the to identify the backup file. (See

    Below!)

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    f 30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    22/30

    4] We need to Add the backup file. Using the mouse, select/push theAddbutton. (See Below!)

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    f 30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    23/30

    5] Locate the backup file in the top window. Using the mouse, select/push the OKbutton. I have selected Northwind.bak

    on C:\ (See Below!)

    6] Using the mouse, select/push the OKbutton. (See Below!)

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    f 30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    24/30

    7] Check the box beside Northwind-Full Database Backup. Using the mouse, select/push the OKbutton. (See Below!)

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    f 30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    25/30

    8] Using the mouse, select/push the OKbutton. (See Below!)

    9] As you can see below, once again we have a Northwind database whose Customer table has 91 records. Tables Order

    Details and Orders have also been restored. This process can be used to databases on other SQL/SQLEXPRESS

    Servers. (See Below!)

    At taching A MSSQL Data Fi les

    1] The techniques above work to backup and restore data from the same database instance. By using attach, we can get

    the data into other database instances.

    2] You might want to download the two files below and copy them into your SQL Server data directory (see below!)

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    f 30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    26/30

    3] Open MSSQL Server Management Studio Express. Right mouse click on Databases and select Attach. (see below!)

    4] Push/Select the Add button. (see below!)

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    f 30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    27/30

    5] Select the LibraryApp.mdf in your SQL Server data directory. (see below!)

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    f 30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    28/30

    6] Open MSSQL Server Management Studio Express. Right mouse click on Databases and select Attach. (see below!)

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    f 30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    29/30

    Other Related Tutorials

    Tutorial: Visual Studio 2008 Install

    Tutorial: Visual Studio 2008 SP1 Install

    Tutorial: Visual Studio Windows Application - Forms - Basic Forms

    Tutorial: Visual Studio Windows Application - Forms - Labels & TextBoxes

    Tutorial: Visual Studio Windows Application - Forms - Buttons & Color Picker

    Tutorial: Visual Studio Windows Application - Forms - Menu Driven Appli cation With Multiple Forms

    Tutorial : Visual Studio Windows Application - Forms - MenuStrip Driven Application

    Tutorial: Visual Studio Windows Application - Forms - Passing-Data Between Parent Child Forms

    Tutorial: Visual Studio Windows App lication - Add ing A Web Browser Component To A Database Form

    Tutorial: Microsft SQL Server Express- 2008 Advanced (With Server Management Studio) Express Install

    Tutorial: MSSQL Database Construction With Server Management Studio

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

    f 30 11/21/2013 11:57 AM

  • 8/13/2019 Import Export Backup MSSQL Database

    30/30

    Tutorial: MSSQL Database Import, Export, & Backup With Server-Management-Studio

    Tutorial: Visual Studio Windows Application - Forms - MSSQL Connections & ComboBoxes

    Tutorial: Visual Studio Windows Application - Forms - MSSQL GUI Connections & DataGrids

    Tutorial: Tutorial: Tutorial: Visual Studio Windows Appl ication - MSSQL Connections To A Library App lication

    Tutorial: Visual Studio Windows Application - Forms - Custom MSSQL Record Lock-Out System For Multi-User

    LibraryApp - 1

    [Database Configuration, Database Authentication, Generic Database Utilities, Etc.]

    Tutorial: Visual Studio Windows Application - Forms - Custom MSSQL Record Lock-Out System For Multi-User

    LibraryApp - 2

    [Query Set Views & Navigation Buttons & Filters & Order By]

    Tutorial: Visual Studio Windows Application - Forms - Custom MSSQL Record Lock-Out System For Multi-User

    LibraryApp - 3

    [Login, RecoordLock DB, Authentication, Configure Dynamic Data Combo, Password Fields, CheckBoxes, & Tab Control]

    Tutorial: Visual Studio Windows Application - Forms - Custom MSSQL Record Lock-Out System For Multi-User

    LibraryApp - 4

    [Edit Mode, Normal Mode, Record-Lock Database, Record-Lockout Timing, Insert Lock Request, Complete Lock

    Request]

    Tutorial: Visual Studio Windows Application - Forms - Custom MSSQL Record Lock-Out System For Multi-User

    LibraryApp - 5

    [Phase In Record Lock-Out System]

    ort-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...