Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 remove ndf file

Author  Topic 

laddu
Constraint Violating Yak Guru

332 Posts

Posted - 2011-02-03 : 12:02:58
Hi,

I noticed that one of sql server 2005 database has mdf and ndf files (no ldf)

When restored the database someone made mistake, instead of typing .ldf, .ndf is added in log file.

Now, how to replace the .ndf file with .ldf

Please advice.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-02-03 : 12:57:31
Detach the database, rename the file, and then attach it back.

Make sure you've got good backups though just in case the attach errors out!

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-02-03 : 12:58:20
You can do it with ALTER DATABASE too, I believe. I don't have BOL in front of me at the moment.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

jeffw8713
Aged Yak Warrior

819 Posts

Posted - 2011-02-03 : 15:34:20
ALTER DATABASE {database} MODIFY FILE (...);
GO

ALTER DATABASE {database} SET OFFLINE WITH ROLLBACK IMMEDIATE; --take database offline for rename
GO

-- rename the file to the same name you used in the MODIFY FILE command

ALTER DATABASE {database} SET ONLINE;
GO

The advantage to this process is that you don't have to worry about resetting the owner after the attach.

Jeff
Go to Top of Page

laddu
Constraint Violating Yak Guru

332 Posts

Posted - 2011-03-08 : 10:31:18

<-- rename the file to the same name you used in the MODIFY FILE command>
you mean , rename file in disk path (eg:C:\Program Files\Microsoft SQL Server\MSSQL10.SQL2008\MSSQL\DATA\Test.mdf)
Go to Top of Page

jeffw8713
Aged Yak Warrior

819 Posts

Posted - 2011-03-08 : 15:48:18
Correct - if your file is currently C:\SQL\MyDatabase.ndf, and you use MODIFY FILE to change it to C:\SQL\MyDatabase.ldf - then, after taking database offline you rename the file to C:\SQL\MyDatabase.ldf and bring the database back online.

Jeff
Go to Top of Page
   

- Advertisement -