Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 stored Procedure

Author  Topic 

glendcruz
Yak Posting Veteran

60 Posts

Posted - 2008-02-14 : 18:17:14
How do you use this stored procedure
sp_attach_db
Can anyone please give me an example

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2008-02-14 : 18:48:52
It is used to "attach" or bring back on-line a database that had previously been "detached" using, you guessed it, sp_detatch_db. Detaching a database removes database and its data and log files, typically .MDF and .LDF files names, from SQL Server's world view. Once the database is detached, you can operate on the files, for instance moving them, like they were regular files.

One way to move a database from one server to another (not necessarily the best way) is to detach it from server X, move the MDF and LDF files to server Y, and then attach the database files on server Y.

Here is the example from BOL:

EXEC sp_attach_db @dbname = N'AdventureWorks',
@filename1 = N'c:\Program Files\Microsoft SQL Server
\MSSQL.1\MSSQL\Data\AdventureWorks_Data.mdf',
@filename2 = N'c:\Program Files\Microsoft SQL Server
\MSSQL.1\MSSQL\Data\AdventureWorks_log.ldf' ;


=======================================
Society is like a stew. If you don't keep it stirred up you get a lot of scum on the top. -Edward Abbey, naturalist and author (1927-1989)
Go to Top of Page

SusanthaB
Starting Member

14 Posts

Posted - 2008-02-15 : 04:40:56
http://msdn2.microsoft.com/en-us/library/aa259611(SQL.80).aspx

Susantha Bathige
Senior DBA, Sri Lanka
Go to Top of Page

elracorey
Starting Member

30 Posts

Posted - 2008-03-03 : 10:24:57
Hi,
I'm trying to install AdventureWorks for SQL Server 2005. I've found the link ok on the codeplex site and the install commences to the point where it finishes successfully (or so it says). But when I go to the install directory, I can't find either the mdf or log file. I've even done a disk search for it.
Anyone had this issue?
Thanks, Lee.
Go to Top of Page
   

- Advertisement -