Import-Export-Backup-MSSQL-Database

http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

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: 1. All hard drives will eventually go bad; a current backup will enable you to restore the databases. 2. 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. 3. 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. 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 Northwind database on Net1. Note that the Northwind database contains 8 tables.

1 of 30

11/21/2013 11:57 AM

Import-Export-Backup-MSSQL-Database

http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

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

2 of 30

11/21/2013 11:57 AM

Import-Export-Backup-MSSQL-Database

http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme...

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 Northwind Database --> 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.bak in directory. Using the mouse, select/push the OK button. (See Below!)

3 of 30

11/21/2013 11:57 AM

. select/push the OK button. (See Below!) 4] Take a look in directory C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup .bak.you will see file Northwind.cs. (See Below!) 4 of 30 11/21/2013 11:57 AM .trinity. 3] The BackUp takes only seconds to complete. Using the mouse..Import-Export-Backup-MSSQL-Database http://www.edu/~thicks/Tutorials/MSSQL-Server-Manageme.

right-mouse-click on the Northwind Database --> Select Delete (See Below!) 2] Using the mouse.Import-Export-Backup-MSSQL-Database http://www. select/push the OK button. 5 of 30 11/21/2013 11:57 AM ... Delete The Original Northwind Database 1] Using the mouse.edu/~thicks/Tutorials/MSSQL-Server-Manageme.trinity.cs.

trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme. 3] Note that the Northwind database is no longer there.Import-Export-Backup-MSSQL-Database http://www. (See Below!) 6 of 30 11/21/2013 11:57 AM ..cs..

bak in directory C:\ (See Below!) IMPORTING PROBLEMS? I have found that students are sometimes successful importing from drive C and sometimes not.Import-Export-Backup-MSSQL-Database http://www.edu/~thicks/Tutorials/MSSQL-Server-Manageme.trinity.cs.1\MSSQL\Backup 7 of 30 11/21/2013 11:57 AM . I have shown the default permissions on folder C:\Program Files\Microsoft SQL Server\MSSQL. They will always have problems importing from the desktop.bak To Create A New Database 1] Suppose we have a copy of our Northwind.. It depends upon the permissions associated with the drive C of the computer. Import//Restore Northwind. In order to consider the permissions we might need. it is best to examine the default folder that MSSQL uses to backup files.. The required permission for the import is SQLServer2005MSSQLUser Below.

trinity. What To Do If I Have Problems Importing: Either Do A] 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. right-mouse-click on Databases --> Select Restore Database (See Below!) 8 of 30 11/21/2013 11:57 AM .cs. A drag file maintains the original file permissions..Import-Export-Backup-MSSQL-Database http://www. it will not have the right permissions.] Or B] Provide full control of the backup file to the SQLServer2005MSSQLUser 2] Using the mouse.edu/~thicks/Tutorials/MSSQL-Server-Manageme. but a copy file acquires the permissions of the host folder.

cs.trinity. Select the From Device radio button. Select the Below!) to identify the backup file. 3] Name the database Northwind.Import-Export-Backup-MSSQL-Database http://www..edu/~thicks/Tutorials/MSSQL-Server-Manageme.. (See 9 of 30 11/21/2013 11:57 AM .

trinity..edu/~thicks/Tutorials/MSSQL-Server-Manageme.. 4] We need to Add the backup file.cs. (See Below!) 10 of 30 11/21/2013 11:57 AM . select/push the Add button.Import-Export-Backup-MSSQL-Database http://www. Using the mouse.

5] Locate the backup file in the top window.Import-Export-Backup-MSSQL-Database http://www..edu/~thicks/Tutorials/MSSQL-Server-Manageme. select/push the OK button. I have selected Northwind. (See Below!) 11 of 30 11/21/2013 11:57 AM .trinity.bak on C:\ (See Below!) 6] Using the mouse. Using the mouse.cs.. select/push the OK button.

select/push the OK button. Using the mouse..trinity.. 7] Check the box beside Northwind-Full Database Backup.Import-Export-Backup-MSSQL-Database http://www. (See Below!) 12 of 30 11/21/2013 11:57 AM .edu/~thicks/Tutorials/MSSQL-Server-Manageme.cs.

select/push the OK button.trinity. (See Below!) 13 of 30 11/21/2013 11:57 AM .Import-Export-Backup-MSSQL-Database http://www.edu/~thicks/Tutorials/MSSQL-Server-Manageme. This process can be used to make a copies of the Northwind database on other SQL/SQLEXPRESS Servers. once again we have a Northwind database whose Customer table has 91 records.. 8] Using the mouse. (See Below!) 9] As you can see below..cs.

Import-Export-Backup-MSSQL-Database http://www.cs.trinity..edu/~thicks/Tutorials/MSSQL-Server-Manageme.bak To Make A Duplicate Database Called Nortwind2.bak in directory C:\ (See Below!) 2] Using the mouse.. Import//Restore Northwind.bak 1] Suppose we have a copy of our Northwind. right-mouse-click on Databases --> Select Restore Database (See Below!) 14 of 30 11/21/2013 11:57 AM .

Select the From Device radio button.Import-Export-Backup-MSSQL-Database http://www..cs. 3] Name the database Northwind2.edu/~thicks/Tutorials/MSSQL-Server-Manageme. 15 of 30 11/21/2013 11:57 AM . Select the (See Below!) to identify the backup file.trinity..

(See Below!) 16 of 30 11/21/2013 11:57 AM . Using the mouse.cs. select/push the Add button..Import-Export-Backup-MSSQL-Database http://www.edu/~thicks/Tutorials/MSSQL-Server-Manageme.trinity.. 4] We need to Add the backup file.

trinity. select/push the OK button..cs. Using the mouse. select/push the OK button.bak on C:\ (See Below!) 6] Using the mouse..Import-Export-Backup-MSSQL-Database http://www. I have selected Northwind. 5] Locate the backup file in the top window. (See Below!) 17 of 30 11/21/2013 11:57 AM .edu/~thicks/Tutorials/MSSQL-Server-Manageme.

Import-Export-Backup-MSSQL-Database http://www.trinity. 7] Check the box beside Northwind-Full Database Backup. Using the mouse. (See Below!) 18 of 30 11/21/2013 11:57 AM ..cs..edu/~thicks/Tutorials/MSSQL-Server-Manageme. select/push the OK button.

.edu/~thicks/Tutorials/MSSQL-Server-Manageme.. This process can be used to make a duplicate copy of the Northwind database on the same SQL/SQLEXPRESS Server. (See Below!) 9] As you can see below.trinity. (See Below!) 19 of 30 11/21/2013 11:57 AM . it can also be used for development. 8] Using the mouse.cs. select/push the OK button. I have also reduced the 91 Customer table records to only 12.Import-Export-Backup-MSSQL-Database http://www. (See Below!) Alter The Original Northwind Database 1] Note that I have deleted the OrderDetail and the Orders tables from the Northwind database. This copy might be used to test procedures and queries. once again we have a Northwind2 database whose Customer table has 91 records.

bak 1] Suppose we have a copy of our Northwind. right-mouse-click on Databases --> Select Restore Database (See Below!) 20 of 30 11/21/2013 11:57 AM .Import-Export-Backup-MSSQL-Database http://www...edu/~thicks/Tutorials/MSSQL-Server-Manageme.bak in directory C:\ (See Below!) 2] Using the mouse.trinity.cs. Restore The Northwind Database From Northwind.

Select the From Device radio button.cs.trinity. 3] Name the database Northwind.. Select the Below!) to identify the backup file. (See 21 of 30 11/21/2013 11:57 AM .edu/~thicks/Tutorials/MSSQL-Server-Manageme.Import-Export-Backup-MSSQL-Database http://www..

(See Below!) 22 of 30 11/21/2013 11:57 AM ..cs. select/push the Add button. 4] We need to Add the backup file..Import-Export-Backup-MSSQL-Database http://www.edu/~thicks/Tutorials/MSSQL-Server-Manageme. Using the mouse.trinity.

Using the mouse.bak on C:\ (See Below!) 6] Using the mouse. I have selected Northwind.. select/push the OK button. (See Below!) 23 of 30 11/21/2013 11:57 AM . 5] Locate the backup file in the top window.edu/~thicks/Tutorials/MSSQL-Server-Manageme.Import-Export-Backup-MSSQL-Database http://www. select/push the OK button.trinity..cs.

Using the mouse.Import-Export-Backup-MSSQL-Database http://www.cs.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme. (See Below!) 24 of 30 11/21/2013 11:57 AM .. 7] Check the box beside Northwind-Full Database Backup.. select/push the OK button.

This process can be used to databases on other SQL/SQLEXPRESS Servers.trinity. once again we have a Northwind database whose Customer table has 91 records. 8] Using the mouse. select/push the OK button.Import-Export-Backup-MSSQL-Database http://www.edu/~thicks/Tutorials/MSSQL-Server-Manageme.cs. we can get the data into other database instances. (See Below!) Attaching A MSSQL Data Files 1] The techniques above work to backup and restore data from the same database instance. Tables Order Details and Orders have also been restored.. 2] You might want to download the two files below and copy them into your SQL Server data directory (see below!) 25 of 30 11/21/2013 11:57 AM .. (See Below!) 9] As you can see below. By using attach.

(see below!) 26 of 30 11/21/2013 11:57 AM .. (see below!) 4] Push/Select the Add button.trinity.edu/~thicks/Tutorials/MSSQL-Server-Manageme. Right mouse click on Databases and select Attach.cs..Import-Export-Backup-MSSQL-Database http://www. 3] Open MSSQL Server Management Studio Express.

. 5] Select the LibraryApp.cs.Import-Export-Backup-MSSQL-Database http://www.. (see below!) 27 of 30 11/21/2013 11:57 AM .trinity.mdf in your SQL Server data directory.edu/~thicks/Tutorials/MSSQL-Server-Manageme.

(see below!) 28 of 30 11/21/2013 11:57 AM .cs.trinity. Right mouse click on Databases and select Attach..Import-Export-Backup-MSSQL-Database http://www.. 6] Open MSSQL Server Management Studio Express.edu/~thicks/Tutorials/MSSQL-Server-Manageme.

Labels & TextBoxes Tutorial: Visual Studio Windows Application .Forms .Basic Forms Tutorial: Visual Studio Windows Application .trinity.Forms .Import-Export-Backup-MSSQL-Database http://www.cs. Other Related Tutorials Tutorial: Visual Studio 2008 Install Tutorial: Visual Studio 2008 SP1 Install Tutorial: Visual Studio Windows Application ...Adding A Web Browser Component To A Database Form Tutorial: Microsft SQL Server Express.edu/~thicks/Tutorials/MSSQL-Server-Manageme.Forms .Menu Driven Application With Multiple Forms Tutorial : Visual Studio Windows Application .Passing-Data Between Parent Child Forms Tutorial: Visual Studio Windows Application .Buttons & Color Picker Tutorial: Visual Studio Windows Application .2008 Advanced (With Server Management Studio) Express Install Tutorial: MSSQL Database Construction With Server Management Studio 29 of 30 11/21/2013 11:57 AM .Forms .Forms .MenuStrip Driven Application Tutorial: Visual Studio Windows Application .Forms .

Custom MSSQL Record Lock-Out System For Multi-User LibraryApp . Etc.Forms .MSSQL Connections & ComboBoxes Tutorial: Visual Studio Windows Application .Custom MSSQL Record Lock-Out System For Multi-User LibraryApp . Password Fields.cs. Database Authentication.Custom MSSQL Record Lock-Out System For Multi-User LibraryApp . Authentication.MSSQL GUI Connections & DataGrids Tutorial: Tutorial: Tutorial: Visual Studio Windows Application .Forms .2 [Query Set Views & Navigation Buttons & Filters & Order By] Tutorial: Visual Studio Windows Application . Configure Dynamic Data Combo. Generic Database Utilities.Forms .Forms .trinity. Complete Lock Request] Tutorial: Visual Studio Windows Application . Record-Lock Database.] Tutorial: Visual Studio Windows Application .1 [Database Configuration. & Backup With Server-Management-Studio Tutorial: Visual Studio Windows Application .3 [Login. & Tab Control] Tutorial: Visual Studio Windows Application . Tutorial: MSSQL Database Import.Custom MSSQL Record Lock-Out System For Multi-User LibraryApp . Insert Lock Request. Record-Lockout Timing. RecoordLock DB..Forms .5 [Phase In Record Lock-Out System] 30 of 30 11/21/2013 11:57 AM .MSSQL Connections To A Library Application Tutorial: Visual Studio Windows Application . Export.edu/~thicks/Tutorials/MSSQL-Server-Manageme.Custom MSSQL Record Lock-Out System For Multi-User LibraryApp .Forms .4 [Edit Mode.. CheckBoxes. Normal Mode.Import-Export-Backup-MSSQL-Database http://www.Forms .

Sign up to vote on this title
UsefulNot useful