怎样用LDF,MDF文件恢复数据库?
我有个数据库AAA,
(删除了注册表相关信息)重装MS SqlServer后,数据库AAA就不出现在集成管理器里。
但在'c:\Progarm ....\Data'里留下两个文件AAA_Data.MDF,AAA_Log.LDF
请问:我怎样用这两个文件恢复数据库。(用Sql语句)
问题点数:20、回复次数:5Top
1 楼WangZWang(先来)回复于 2004-12-02 10:53:51 得分 1
附加数据库Top
2 楼comszsoft(星星点灯)回复于 2004-12-02 10:57:16 得分 2
database-->所有任务——>attach databaseTop
3 楼xuam()回复于 2004-12-02 10:57:16 得分 12
Syntax
sp_attach_db [ @dbname = ] 'dbname'
, [ @filename1 = ] 'filename_n' [ ,...16 ]
Arguments
[@dbname =] 'dbname'
Is the name of the database to be attached to the server. The name must be unique. dbname is sysname, with a default of NULL.
[@filename1 =] 'filename_n'
Is the physical name, including path, of a database file. filename_n is nvarchar(260), with a default of NULL. There can be up to 16 file names specified. The parameter names start at @filename1 and increment to @filename16. The file name list must include at least the primary file, which contains the system tables that point to other files in the database. The list must also include any files that were moved after the database was detached.
Return Code Values
0 (success) or 1 (failure)
Result Sets
None
Remarks
sp_attach_db should only be executed on databases that were previously detached from the database server using an explicit sp_detach_db operation. If more than 16 files must be specified, use CREATE DATABASE with the FOR ATTACH clause.
If you attach a database to a server other than the server from which the database was detached, and the detached database was enabled for replication, you should run sp_removedbreplication to remove replication from the database.
Permissions
Only members of the sysadmin and dbcreator fixed server roles can execute this procedure.
Examples
This example attaches two files from pubs to the current server.
EXEC sp_attach_db @dbname = N'pubs',
@filename1 = N'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf',
@filename2 = N'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs_log.ldf'
Top
4 楼zzzxxxcccvvv(zxc)回复于 2004-12-02 11:09:40 得分 0
Thanks All!
Especially thanks for xuam() !
to xuam()
我也喜欢多使用英文,
但限于自己英文水平,超过100个单词我就晕!@_@! 呵!Top
5 楼qizhanfeng(glacier)回复于 2004-12-02 11:10:28 得分 5
EXEC sp_attach_db @dbname = N'new_db',
@filename1 = N'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf',
@filename2 = N'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.ldfTop




