MS SQL Server
  Home arrow MS SQL Server arrow Page 3 - SQL Server 2005 Introduction to SQL Server...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MS SQL SERVER

SQL Server 2005 Introduction to SQL Server Management Studio
By: MSDN Virtual Labs
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 18
    2006-01-12

    Table of Contents:
  • SQL Server 2005 Introduction to SQL Server Management Studio
  • Exercise 1: Exploring the Environment
  • Exercise 2: Attaching a Database
  • Exercise 3: Exploring an Existing Database
  • Exercise 4: Creating a New Database
  • Exercise 5: Setting up Database Access

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    SQL Server 2005 Introduction to SQL Server Management Studio - Exercise 2: Attaching a Database


    (Page 3 of 6 )

    Scenario

    In this exercise, you will attach the AdventureWorks database using the “Attach Database” option in the SQL Server Management Studio Object Explorer.

    Attaching a database means making all the database files available to your SQL Server, just as if you had created the database on the current server. Detaching a database allows you to move the physical files and reattach those files from a new physical location, or to make a copy of the files to use on another server (perhaps a test or development server).

    Because the primary file contains the locations of all the other files in a database, if all the files are in their original location (as stored in the primary file) you only need to specify the primary file when attaching the database. SQL Server will read the information in the primary file and attach all the associated files for the database.

    However, if the files are not all in the original location, the information stored in the primary file may not be sufficient for SQL Server to find and attach all the database files. You will then need to specify the exact physical location of each database file that is not in the location it was when the database was detached.

    When a database is detached, SQL Server will do a checkpoint in the database, so all the committed transactions are written to the disk files.

                TASKS                       DETAILED STEPS

    1. If the database is already attached, detach it.
       
        1. In the Object Explorer, expand localhost or the name of your server (if it's not already expanded), then expand the Databases folders.
        2. If the AdventureWorks database is in the list, right-click on it. Otherwise, skip to the Attach the AdventureWorks database task below.
        3. Point to Tasks, and then click Detach.
        4. In the Detach Database dialog box, click OK. You may have to double click the title bar to see the OK button.
    2. Attach the AdventureWorks database.
       
        1. In the Object Explorer, right-click on the Databases folder, and click Attach.
        2. In the Attach Database(s) dialog box, click Add.
        3. Locate and select the following master file for the AdventureWorks database (C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AdventureWorks_Data.mdf), and click OK.

          Note that the Attach Database dialog box is not modal. This means that you can go back to the Management Studio and look for other information you might require while filling in the dialog box.
        4. Verify that there are two files listed in the AdventureWorks database details section in the bottom half of the Attach Database(s) dialog box.
        5. Click OK to attach the database. You may have to double click the title bar to see the OK button.
    3. Use the Object Explorer to Verify the AdventureWorks Database.

        1. Collapse and expand the Databases folder in the Object Explorer.
        2. If the AdventureWorks database doesn’t appear, right-click the Databases folder and select Refresh.
        3. Expand the AdventureWorks database.
        4. Expand the Tables folder, and verify that there are several dozen tables.
        5. In the Solution Explorer, open the Queries folder under Exercise 2, and double click the file DatabaseProperties.sql.

          USE AdventureWorks
          SELECT DATABASEPROPERTYEX('AdventureWorks', 'Status')
          SELECT DATABASEPROPERTYEX('AdventureWorks', 'Recovery')
          SELECT DATABASEPROPERTYEX('AdventureWorks', 'Collation')
          SELECT DATABASEPROPERTYEX('AdventureWorks', 'Updateability')
          SELECT DATABASEPROPERTYEX('AdventureWorks', 'UserAccess')
          SELECT DATABASEPROPERTYEX('AdventureWorks', 'IsAutoCreateStatistics')
          SELECT DATABASEPROPERTYEX('AdventureWorks', 'IsAutoShrink')

        6. Press F5 or click the Execute button on the toolbar to execute the batch. If requested, respond to the Connect to SQL Server dialog box.
        7. Examine the values returned for the various database properties.

    More MS SQL Server Articles
    More By MSDN Virtual Labs


       · We hope you found this article from MSDN Virtual Labs to be enjoyable and...
       · Where are the projects for the SQL labs?Select C:\SQL Labs\Lab...
       · Access Virtual Labs online at microsoft.com -> Learning -> Virtual Labs on MSDN
     

    MS SQL SERVER ARTICLES

    - Completing the Introduction to Transact-SQL
    - A Brief Introduction to Transact-SQL
    - Lookups and Blocking Bad Data
    - Field Validation Rules for Blocking Bad Data
    - Using Masks to Block Bad Data
    - Blocking Bad Data
    - Using @@ROWCOUNT and TABLE Variables for Dat...
    - How to Use Variables, IF and CASE in Databas...
    - Creating Important Aspects of Notification S...
    - Working wth Variables in Database Interactio...
    - Delving Deeper into Notification Services
    - Notification Services
    - Building a Multi-table Report with SQL 2005 ...
    - A Secure Way of Building Connection Strings
    - Transferring a Database Using the SSIS Desig...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT