This site uses cookies to deliver our services. By using this site, you acknowledge that you have read and understand our Cookie and Privacy policy. Your use of Kontext website is subject to this policy. Allow Cookies and Dismiss

SQL Server 附加没有日志文件ldf的数据库mdf的方法

757 views 0 comments last modified about 9 years ago Raymond Tang

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

Related pages

Querying Teradata and SQL Server - Tutorial 1: The SELECT Statement

30524 views   7 comments last modified about 4 years ago

SELECT is one of the most commonly used statements. In this tutorial, I will cover the following items: Two of the principal query clauses—FROM and SELECT Data Types Built-in functions CASE expressions and variations like ISNULL and COALESCE. * The functio...

View detail

Querying Teradata and SQL Server - Tutorial 2 Filtering and Sorting

3160 views   2 comments last modified about 4 years ago

Tutorial –1 For Teradata developers, if you have no SQL Server installed, please go to the following link to download the SQL Server 2014 Expression Edition. ...

View detail

Querying Teradata and SQL Server - Tutorial 0: Preparation

2847 views   0 comments last modified about 4 years ago

In this serial, I will compare Teradata SQL with T-SQL with samples provided. This is mainly prepared for SQL Server DBAs, Developers and other users to help them quickly master the common used SQLs in Teradata platform. Similar to T-SQL, Teradata SQL implements most part of the ANSI SQL with ext...

View detail

[SQL Server 2012] 使用自带功能简化SQL

795 views   0 comments last modified about 6 years ago

在低版本SQL Server中,对于一些常用的查询功能,我们可能需要运用复杂的逻辑,如临时表,游标等等来实现,这样可能会导致代码难维护,同时产生性能问题。本文将简述用自带的功能去简单的实现这些操作。 注意:一些功能仅在SQL Server 2012以及以上版本支持。 1.查询分页 (OFFSET, FETCH) 在很多Web应用程序中,我们需要实现分页功能,在过去,我们往往通过top语句实现或者通过ROW_NUMBER;在2012中加入了FETECH以及OFFSET标准SQL中支持的功能。下面的例子是查询第11到20行数据: ...

View detail

将远程 Sql Server 服务器上的数据库备份到本地的方法

623 views   0 comments last modified about 10 years ago

首先,必须知道数据库服务器的地址(IP),连接用户名和密码、其次,可以按照下面几种方式进行:

View detail

因为数据库正在使用,所以未能获得对数据库的排它访问权 解决办法

234 views   0 comments last modified about 11 years ago

恢复数据库的时候遇到这个错误解决办法

View detail

Add comment

Please login first to add comments.  Log in New user?  Register

Comments (0)

No comments yet.