The below steps applies to MS SQL Server 2008
A. Make sure you enabled database instance to use FILESTREAM as instructed here:
http://msdn.microsoft.com/en-us/library/cc645923.aspx
B. If you downloaded Adventureworks from codeplex, make sure you have set the right user permissions to these files
C. Copy AdventureWorks2008_Data.mdf and AdventureWorks2008_Log.ldf to
‘C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\’
If you see a folder called ‘Documents’ in the downloaded files set, then copy this folder also to ‘C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\’
D. In the managment studio, open new query window and execute the below code: [Change the files path accordingly]
| T-SQL | | copy code | | ? |
| 1 | USE [master] |
| 2 | GO |
| 3 | CREATE DATABASE [Adventureworks] ON |
| 4 | ( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\AdventureWorks2008_Data.mdf' ), |
| 5 | ( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\AdventureWorks2008_Log.ldf' ) |
| 6 | FOR ATTACH |
| 7 | GO |
| 8 | IF not exists (SELECT name FROM master.sys.databases sd WHERE name = N'Adventureworks' and SUSER_SNAME(sd.owner_sid) = SUSER_SNAME() ) EXEC [Adventureworks].dbo.SP_CHANGEDBOWNER @loginame=N'sa', @MAP=FALSE |
| 9 | GO |
OR you can attach a databse either using MS:
1. In SQL Server Management Studio Object Explorer, connect to an instance of the Microsoft SQL Server Database Engine, and then expand that instance.
2. Right click Databases, then Tasks, and then click Attach.
3. In the Attach Databases dialog box, to specify the database to be attached, click Add; and in the Locate Database Files dialog box, select the disk drive where the database resides and expand the directory tree to find and select the .mdf file of the database; for example: C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\AdventureWorks2008_Data.mdf
Optionall : Specify a different name, Change the ownership
4. When you are ready to attach the database, click OK.
Posted: July 14th, 2009
Categories: T-SQL
Tags: AdvenureWorks, database, MS SQL Server 2008
Comments: No Comments.
Categories: T-SQL
Tags: AdvenureWorks, database, MS SQL Server 2008
Comments: No Comments.