|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Monday, May 20, 2013 1:07 PM
Points: 18,733,
Visits: 12,332
|
|
|
|
|
|
Ten 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
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Today @ 11:23 AM
Points: 836,
Visits: 1,215
|
|
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.
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 3:28 PM
Points: 37,730,
Visits: 29,996
|
|
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
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Thursday, February 14, 2013 2:39 PM
Points: 311,
Visits: 277
|
|
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.
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Today @ 6:39 AM
Points: 9,376,
Visits: 6,472
|
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Monday, May 20, 2013 1:47 AM
Points: 778,
Visits: 1,047
|
|
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
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Thursday, May 02, 2013 3:45 PM
Points: 3,748,
Visits: 928
|
|
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
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 5:11 PM
Points: 7,104,
Visits: 7,168
|
|
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 Que conclure à la fin de tous mes longs propos? C'est que les préjugés sont la raison des sots. (Voltaire, 1756)
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Sunday, November 11, 2012 2:23 AM
Points: 51,
Visits: 47
|
|
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
|
|
|
|