Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

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)

Comments

No comments.

Leave a Comment

Please register or log in to leave a comment.