Keywords: how to attach database without log file

今天一个朋友的数据库日志文件因为误操作丢失了,现在他想重新附加却不成功。

对于这种情况我之前很真没遇到过,因为我对于数据库相关的文件总会有备份后的备份

按照他提供的一个网上的方法,特别的复杂,结果还不能成功执行

其实根本不用那么复杂的,直接一条语句或者在企业管理器中就可以很简单的实现。

一,企业管理器中实现

重新附加:在对象资源管理器中,右击“数据库”节点,在ContextMenu中选择附加,在对话框中选择好mdf文件

这个时候会提示找不到日志文件,选择日志文件这行,然后点击右下角的删除按钮,这样就会创建新的日志文件,所以请确保日志文件对应目录需要写入权限

这样数据库就附加成功了,不过以前的日志文件都丢失了,所以平时操作应该特别的注意

二,sql 语句

USE [master]

GO

CREATE DATABASE [TestDB] ON

( FILENAME = N'D:\mydb.mdf' )--红色部分是mdf文件路径

FOR ATTACH

GO

See: http://www.sqlprof.com/blogs/sqlserver/archive/2008/04/17/how-to-attach-a-database-without-a-transaction-log-file-ldf.aspx

info Last modified by Raymond at 6 years ago * This page is subject to Site terms.

More from Kontext

visibility 14297
thumb_up 0
access_time 6 years ago

SQL Server Compact 4.0 (CE 4.0) is a free SQL Server embedded database ideal for building standalone and occasionally connected applications for mobile devices, desktops, Web clients and others. In one of my projects, I used it as the database for logging errors, which assumes the errors will onl...

open_in_new SQL Server

visibility 689
thumb_up 0
access_time 7 years ago

SQL Server provides a batch of great features to build robust, high-performance and scalable data solutions. ...

open_in_new SQL Server

visibility 1180
thumb_up 0
access_time 7 years ago

Serial: An Introduction to SQL Server Features Case Scenario In the previous articles of this serial, I’ve introduced how to use SQL Server as database for online transaction proces...

open_in_new SQL Server

visibility 4489
thumb_up 1
access_time 7 years ago

Serial: An Introduction to SQL Server Features Case Scenario For this ETL project, the requirements are listed below: Sales data will be pushed to specified shared fold...

open_in_new SQL Server

info About author

comment Comments (0)

comment Add comment

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

No comments yet.

Dark theme mode

Dark theme mode is available on Kontext.

Learn more arrow_forward

Kontext Column

Created for everyone to publish data, programming and cloud related articles. Follow three steps to create your columns.


Learn more arrow_forward