Subscribe Links

Subscribe to newsletter


Powered by TypePad
Attach database without log file and rename database

19 August,2011 by Jack Vamvas

Assuming the database was detached successfully , this t-sql code will attach a mdf file  without a log file . It will also reattach the database with a new database name.

If you are first detaching a database read Drop Connections with ROLLBACK IMMEDIATE to allow a Detach database


USE [master]
CREATE DATABASE [myTestDatabase] ON 
( FILENAME = N'E:\Program Files\Microsoft SQL Server\Data\MSSQL.1\MSSQL\Data\myTestDatabase.mdf' ) 
if exists (select name from master.sys.databases sd where name = N'myTestDatabase ' and SUSER_SNAME(sd.owner_sid) = SUSER_SNAME() ) EXEC [myTestDatabase].dbo.sp_changedbowner @loginame=N'sa', @map=false

 Read More

Detach and Offline for moving databases - SQL Server DBA

Drop Connections with ROLLBACK IMMEDIATE to allow a Detach database

SQL Kill connections to a database - SQL Server DBA

Author: Jack Vamvas (


Subscribe to

Latest posts delivered to you daily

Delivered by FeedBurner

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.


Post a comment | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer