# Problem reattaching SQL database

**URL:** https://boards.straightdope.com/t/problem-reattaching-sql-database/647376
**Category:** Factual Questions
**Created:** [January 16, 2013, 1:25pm UTC](https://boards.straightdope.com/t/problem-reattaching-sql-database/647376 "2013-01-16T13:25:42Z")
**Posts on this page:** 7
**Page:** 2

<div class="post-metadata">

### Author: ![cwthree](https://avatars.discourse-cdn.com/v4/letter/c/9de0a6/32.png) [@cwthree](https://boards.straightdope.com/u/cwthree)
#### Post date: [January 17, 2013, 1:04am UTC](https://boards.straightdope.com/t/problem-reattaching-sql-database/647376/21 "2013-01-17T01:04:29Z")

</div>

How likely is it that the log file contains uncommitted transactions? If the answer is “exceedingly unlikely,” you should be able to reattach the data file without the log file. Open a query window, make sure you’re in the master database, and run:

EXEC sp\_attach\_single\_file\_db @dbname=‘XXXX’,@physname=N’C:\xxxx1.mdf’  
GO

If the mdf file is clean, SQL Server should attach the data file and create a new log file.

---

<div class="post-metadata">

### Author: ![Clothahump](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@Clothahump](https://boards.straightdope.com/u/Clothahump)
#### Post date: [January 17, 2013, 5:02am UTC](https://boards.straightdope.com/t/problem-reattaching-sql-database/647376/22 "2013-01-17T05:02:13Z")

</div>

“We don’ need no steenkin’ backups!”, said no DBA ever.

I agree with the concept of backing up the original database, then restoring it to the new location.

---

<div class="post-metadata">

### Author: ![Dog80](https://avatars.discourse-cdn.com/v4/letter/d/6bbea6/32.png) [@Dog80](https://boards.straightdope.com/u/Dog80)
#### Post date: [January 17, 2013, 12:02pm UTC](https://boards.straightdope.com/t/problem-reattaching-sql-database/647376/23 "2013-01-17T12:02:30Z")

</div>

Thanks for all the support so far!

Luckily I did backup the database before doing the detach/attach thing. But I don’t currently have it available.

Another question: Where do I run these commands? All I have available is an icon in the notification area that shows that the server is running, and an application called dbmanager.exe (I guess this is a frontend GUI) that I did the backup and detach/attach from.

Also another problem: Seems like the physical computer has problems too, it says that the database is flagged as SUSPECT and cannot open it.

---

<div class="post-metadata">

### Author: ![redtail23](https://avatars.discourse-cdn.com/v4/letter/r/3e96dc/32.png) [@redtail23](https://boards.straightdope.com/u/redtail23)
#### Post date: [January 17, 2013, 5:09pm UTC](https://boards.straightdope.com/t/problem-reattaching-sql-database/647376/24 "2013-01-17T17:09:57Z")

</div>

Yay for backups!

Look in the Program Files on the server. You should have SQL Server Management Studio in there under Microsoft.

That’s where you can run the stuff we’re talking about.

The only question is how they’ve got the user access set up - you may have to get the vendor to give you login details.

You’ve definitely got some corruption.

Hopefully it is just the files rather than in the database itself.

You need to get that backup file.

**Troutman** , lol. OK, yeah, you can mess up a db if you’re restoring over, I was talking about making copies. You may get a bad backup, but that’s not going to muck the original.

**cwthree** , that’s the question, isn’t it. s/he’s got no idea of the state of anything related to the database.

---

<div class="post-metadata">

### Author: ![Spectre\_of\_Pithecanthropus](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/spectre_of_pithecanthropus/32/12343_2.png) [@Spectre\_of\_Pithecanthropus](https://boards.straightdope.com/u/Spectre_of_Pithecanthropus)
#### Post date: [January 17, 2013, 9:57pm UTC](https://boards.straightdope.com/t/problem-reattaching-sql-database/647376/25 "2013-01-17T21:57:41Z")

</div>

> [@Clothahump](#):
>
> “We don’ need no steenkin’ backups!”, said no DBA ever.
> 
> I agree with the concept of backing up the original database, then restoring it to the new location.

This has worked for me in similar circumstances.

---

<div class="post-metadata">

### Author: ![Dog80](https://avatars.discourse-cdn.com/v4/letter/d/6bbea6/32.png) [@Dog80](https://boards.straightdope.com/u/Dog80)
#### Post date: [January 18, 2013, 12:50am UTC](https://boards.straightdope.com/t/problem-reattaching-sql-database/647376/26 "2013-01-18T00:50:38Z")

</div>

Ok guys, I got hold of the backup file and restored everything. Now it works both in the physical and virtual machines.

I believe the db got corrupted because at some time I pulled out the USB stick that contained it without stopping the server first. Not a good idea to keep a database on removable media.

---

<div class="post-metadata">

### Author: ![TroutMan](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/troutman/32/6721_2.png) [@TroutMan](https://boards.straightdope.com/u/TroutMan)
#### Post date: [January 18, 2013, 1:52am UTC](https://boards.straightdope.com/t/problem-reattaching-sql-database/647376/27 "2013-01-18T01:52:25Z")

</div>

> [@Dog80](#):
>
> Ok guys, I got hold of the backup file and restored everything. Now it works both in the physical and virtual machines.

That’s good news, congrats!

> [@](#):
>
> I believe the db got corrupted because at some time I pulled out the USB stick that contained it without stopping the server first. Not a good idea to keep a database on removable media.

Heh, that will do it.

[Previous page](https://boards.straightdope.com/t/problem-reattaching-sql-database/647376.md?page=1)
