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
 General SQL Server Forums
 New to SQL Server Programming
 how to attach the detached database

Author  Topic 

sunsanvin
Master Smack Fu Yak Hacker

1274 Posts

Posted - 2007-10-01 : 02:27:15
Dear All,
i've detached my database. how to attache thesame again?

Vinod
Even you learn 1%, Learn it with 100% confidence.

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-10-01 : 02:31:49
Make use of sp_attach_db stored proc.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-10-01 : 02:36:53
See also: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210&SearchTerms=single%20file%20attach,sp_attach_single_file_db,attach,detach,Reattach
Go to Top of Page

sunsanvin
Master Smack Fu Yak Hacker

1274 Posts

Posted - 2007-10-01 : 02:37:12
i've passed the parametre as the database name. but i'm getting error....
shall i provide the path of the datafile and logfile?

Vinod
Even you learn 1%, Learn it with 100% confidence.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-10-01 : 02:44:08
What's the error message you are getting?
Go to Top of Page

sunsanvin
Master Smack Fu Yak Hacker

1274 Posts

Posted - 2007-10-01 : 02:47:00
i'm getting the error like this

Procedure 'sp_attach_db' expects parameter '@filename1', which was not supplied.

Vinod
Even you learn 1%, Learn it with 100% confidence.
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-10-01 : 02:51:00
Did you at least check the documentation for sp_attach_db before using it?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

sunsanvin
Master Smack Fu Yak Hacker

1274 Posts

Posted - 2007-10-01 : 02:52:23
i've gone through the enterprise manager, and by showing the MDF file path, i've attached the database....
thank you very much...harsh and kiristen....

and what exactly is the use of attaching and detaching the database?

Vinod
Even you learn 1%, Learn it with 100% confidence.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-10-01 : 03:26:28
the use is to quickly move it between servers if needed.

it's not used very often but it's there to use...


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2007-10-01 : 05:29:43
Also , although this not the best way to do things, you can quickly create a new Log file by detaching and then reattaching without specifying a Log file, this will create a fresh Log file. Useful , if you're having emergency space issues

Jack Vamvas
--------------------
Search IT jobs from multiple sources- http://www.ITjobfeed.com/SQL
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2007-10-01 : 16:10:06
It's aso a quick and dirty way of i.e. duplicating your database for dev/testing purposes...often you want to run tests on production data and if you can afford to take your prod database offline.

--
Lumbago
"Real programmers don't document, if it was hard to write it should be hard to understand"
Go to Top of Page
   

- Advertisement -