Created
          January 18, 2021 21:47 
        
      - 
      
- 
        Save MartinMiles/a6a69f92425843d2da002c25488b8151 to your computer and use it in GitHub Desktop. 
    Re-attach SQL database from an MDF file (good for detaching for removing huge LDF)
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | -- you should have you DB up& running (for example, after restoring) | |
| -- then you need to detach the database and delete that huge .LDF file | |
| -- it will get re-created upon re-attaching by using the below command | |
| CREATE DATABASE databasename | |
| ON (FILENAME= 'c:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\databasename_web.mdf') | |
| FOR ATTACH_REBUILD_LOG | |
| GO | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment