/*============================================================================
  File:     CreateForAttach.sql

  Summary:  This script connects to a SQL Server 2000 instance and detaches
			a database. Subsequently, it copies the database files as well as
			renames them in the appropriate SQL Server 2005 directory - using
			!!copy. Once copied, it re-attaches the original 2000 database
			and then uses CREATE FOR ATTACH in SQL Server 2005.
			
  Date:     March 15, 2005

  SQL Server Version: 9.00.1090 (IDW13)
------------------------------------------------------------------------------
  Copyright (C) 2005 Kimberly L. Tripp, SYSolutions, Inc.
  All rights reserved.

  For more scripts and sample code, check out 
    http://www.SQLskills.com

  This script is intended only as a supplement to demos and lectures
  given by Kimberly L. Tripp.  
  
  THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF 
  ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED 
  TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  PARTICULAR PURPOSE.
============================================================================*/

:CONNECT RoadRunner64

exec sp_detach_db pubs
go

:CONNECT RoadRunner64\SQLDev01

!!copy "C:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf" "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\ForAttachPubsData.mdf"
!!copy "C:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs_log.ldf" "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\ForAttachPubsLog.ldf"
go

:CONNECT RoadRunner64

exec sp_attach_db pubs, 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf'
go

:CONNECT RoadRunner64\SQLDev01

CREATE DATABASE pubs 
ON PRIMARY 
   (FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\ForAttachPubsData.mdf')
LOG ON (FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\ForAttachPubsLog.ldf')
FOR ATTACH;