Detach and Attach SQL Database by Stored Procedure

Database

Detach and Attach SQL Database by Stored Procedure

How can I detach and attach the SQL database by SP. please help because I want to change the location of my database.

Tags (1)
3 REPLIES

Re: Detach and Attach SQL Database by Stored Procedure

Hi Robin,

to detach the SQLdatabase, use the following code:

sp_detach_db [ @dbname= ] 'database_name'

[ , [ @skipchecks= ] 'skipchecks' ]

[ , [ @keepfulltextindexfile = ] 'KeepFulltextIndexFile' ]

to attach the SQL database, use the following code:

sp_attach_db [ @dbname= ] 'dbname'
, [ @filename1= ] 'filename_n' [ ,...16 ]

All the best!!

Re: Detach and Attach SQL Database by Stored Procedure

Thanks a lot Dazy for your kind help. Can you please tell me the way to attach the database using SQL Server Management Studio?

I think, there is a corruption in my database so please suggest any utility to repair it. I am not so much aware of SQL server.

Thanks in advance.

Re: Detach and Attach SQL Database by Stored Procedure

Hi Robin,

First of all, please take the latest backup of your database.

To attach the files using SSMS, follow these steps:

  1. Right click on the connected instance and select attach.
  2. A attach dialog box will appear on the screen.
  3. Now click on the Add button and specify your database.
  4. Select the database from the disk drive.
  5. Now verify and click on the OK button to start attach process.

I can suggest one tool which is paid but, I did not use it, so read all the information carefully to purchase it. I am sharing the link with you

http://www.stellarinfo.com/sql-recovery.htm

Good Luck!