Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««123»»

Create Database Expand / Collapse
Author
Message
Posted Thursday, June 21, 2012 7:51 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 4:53 PM
Points: 21,617, Visits: 15,271
Thomas Abraham (6/21/2012)
tommyh (6/21/2012)
Works just fine to attach a database with just "for attach" with only one log file.

/T


I figured it would. But it's nice to have it confirmed. (Yes, I don't always trust BOL.) Thanks for the effort!


I have used the For Attach method several times as well.




Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1319303
Posted Thursday, June 21, 2012 8:29 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, January 31, 2013 8:53 AM
Points: 1,176, Visits: 778
Answered off the cuff believing that FOR ATTACH rebuilds the log.

Thanks tommyh for confirming... Missed the earlier post

Cheers
Post #1319339
Posted Thursday, June 21, 2012 9:38 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 10:27 AM
Points: 1,300, Visits: 2,250
SQLRNNR (6/21/2012)
Thomas Abraham (6/21/2012)
tommyh (6/21/2012)
Works just fine to attach a database with just "for attach" with only one log file.

/T


I figured it would. But it's nice to have it confirmed. (Yes, I don't always trust BOL.) Thanks for the effort!


I have used the For Attach method several times as well.


I've done this as well without the log file for various reasons.
Post #1319416
Posted Thursday, June 21, 2012 11:14 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 4:14 PM
Points: 42,747, Visits: 35,835
Worth noting that the attach will only succeed if the database was cleanly shut down before the log was deleted. Otherwise the attach (even with Attach_rebuild_log) will fail.


Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1319490
Posted Thursday, June 21, 2012 2:11 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, April 30, 2014 11:35 AM
Points: 311, Visits: 284
BOL citation:

FOR ATTACH [ WITH < attach_database_option > ]

Specifies that the database is created by attaching an existing set of operating system files. There must be a <filespec> entry that specifies the primary file. The only other <filespec> entries required are those for any files that have a different path from when the database was first created or last attached. A <filespec> entry must be specified for these files.

FOR ATTACH requires the following:

All data files (MDF and NDF) must be available.

If multiple log files exist, they must all be available.

[highlight=#ffff11] If a read/write database has a single log file that is currently unavailable, and if the database was shut down with no users or open transactions before the attach operation, FOR ATTACH automatically rebuilds the log file and updates the primary file. [/highlight]In contrast, for a read-only database, the log cannot be rebuilt because the primary file cannot be updated. Therefore, when you attach a read-only database with a log that is unavailable, you must provide the log files, or the files in the FOR ATTACH clause.
Post #1319634
Posted Thursday, June 21, 2012 2:20 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 8:15 AM
Points: 13,532, Visits: 10,402
Pretty easy if you had to attach the AdventureWorks MDF files multiple times



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1319640
Posted Friday, June 22, 2012 1:46 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Yesterday @ 1:24 AM
Points: 952, Visits: 1,157
A simple one for me thank you very much.

“When I hear somebody sigh, ‘Life is hard,’ I am always tempted to ask, ‘Compared to what?’” - Sydney Harris
Post #1319801
Posted Friday, June 22, 2012 8:50 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 4:08 PM
Points: 3,794, Visits: 1,134
Thanks for the question.

I agree that both options may be correct, depending if the database was shut down cleanly AND only one log file existed for the database file. BOL specifies:

- "If multiple log files exist, they must all be available."

and

- "If a read/write database has a single log file that is currently unavailable, and if the database was shut down with no users or open transactions before the attach operation, FOR ATTACH automatically rebuilds the log file and updates the primary file."

in the FOR_ATTACH option.

"El" Jerry.


"El" Jerry.

"A watt of Ottawa" - Gerardo Galvan

To better understand your help request, please follow these best practices.
Post #1319999
Posted Wednesday, July 18, 2012 11:24 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Today @ 4:28 PM
Points: 8,677, Visits: 9,203
Like those who commented earlier, I think both options work (provided there was a clean shutdown). I picked the second because although I knew the first optioopn would also work I guessed that the question's author didn't.

Tom
Post #1331665
Posted Tuesday, July 31, 2012 10:34 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, December 23, 2013 12:51 AM
Points: 56, Visits: 53
Why don't you remove a question or clarify it when it is clearly wrong and both answers are working.

I have tested it on my SQL Server and the "wrong" option works fine.

Soren
Post #1338295
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse