Blog Post

Attach database without log file and rename database

,

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,.

 

USE [master]
GO
CREATE DATABASE [myTestDatabase] ON 
( FILENAME = N'E:\Program Files\Microsoft SQL Server\Data\MSSQL.1\MSSQL\Data\myTestDatabase.mdf' ) 
 FOR ATTACH
GO
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
GO

Author: Jack Vamvas (http://www.sqlserver-dba.com)


Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating