问题的描述是这样的:标题: Microsoft SQL Server Management Studio ------------------------------附加数据库 对于 服务器“YOUR-EFAC313A92”失败。 (Microsoft.SqlServer.Smo)有关帮助信息,请单击: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.1399.00&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=附加数据库+Server&LinkId=20476------------------------------ 其他信息:执行 Transact-SQL 语句或批处理时发生了异常。 (Microsoft.SqlServer.ConnectionInfo)------------------------------未能在 sysindexes 中找到数据库 ID 7 中对象 ID 1 的索引 ID 1 对应的行。请对 sysindexes 运行 DBCC CHECKTABLE。 Could not find row in sysindexes for database ID 7, object ID 1, index ID 1. Run DBCC CHECKTABLE on sysindexes. 未能打开新数据库 'db_CRM'。CREATE DATABASE 将终止。 (Microsoft SQL Server,错误: 602)有关帮助信息,请单击: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=602&LinkId=20476------------------------------ 按钮:确定 ------------------------------
------------------------------附加数据库 对于 服务器“YOUR-EFAC313A92”失败。 (Microsoft.SqlServer.Smo)有关帮助信息,请单击: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.1399.00&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=附加数据库+Server&LinkId=20476------------------------------
其他信息:执行 Transact-SQL 语句或批处理时发生了异常。 (Microsoft.SqlServer.ConnectionInfo)------------------------------未能在 sysindexes 中找到数据库 ID 7 中对象 ID 1 的索引 ID 1 对应的行。请对 sysindexes 运行 DBCC CHECKTABLE。
Could not find row in sysindexes for database ID 7, object ID 1, index ID 1. Run DBCC CHECKTABLE on sysindexes.
未能打开新数据库 'db_CRM'。CREATE DATABASE 将终止。 (Microsoft SQL Server,错误: 602)有关帮助信息,请单击: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=602&LinkId=20476------------------------------
按钮:确定
------------------------------
对于单个文件,可以用 SP_ATTACH_SINGLE_FILE_DB,如
SP_ATTACH_SINGLE_FILE_DB @DBNAME ='DBName',
@PHYSNAME = 'D:\DATABASE\DBName.MDF'
sp_attach_single_file_db
将只有一个数据文件的数据库附加到当前服务器。
EXEC sp_attach_single_file_db @dbname = 'pubs',
@physname = 'c:\Data\pubs.mdf'
我没有找到能输入命令的地方呀。数据库的MDF和LDF是没有问题的,我买了本书,是书里的光碟带的。
---------------------------查询分析器执行啊
C:\Program Files\Microsoft SQL Server\80\Tools\Binn\isqlw.exe
USE MASTERGOALTER procedure sp_attach_db
@dbname sysname
, @filename1 nvarchar(260)
, @filename2 nvarchar(260) = NULL
, @filename3 nvarchar(260) = NULL
, @filename4 nvarchar(260) = NULL
, @filename5 nvarchar(260) = NULL
, @filename6 nvarchar(260) = NULL
, @filename7 nvarchar(260) = NULL
, @filename8 nvarchar(260) = NULL
, @filename9 nvarchar(260) = NULL
, @filename10 nvarchar(260) = NULL
, @filename11 nvarchar(260) = NULL
, @filename12 nvarchar(260) = NULL
, @filename13 nvarchar(260) = NULL
, @filename14 nvarchar(260) = NULL
, @filename15 nvarchar(260) = NULL
, @filename16 nvarchar(260) = NULL
, @filename17 nvarchar(260) = NULL
, @filename18 nvarchar(260) = NULL
, @filename19 nvarchar(260) = NULL
, @filename20 nvarchar(260) = NULL
, @filename21 nvarchar(260) = NULL
, @filename22 nvarchar(260) = NULL
, @filename23 nvarchar(260) = NULL
, @filename24 nvarchar(260) = NULL
, @filename25 nvarchar(260) = NULL
, @filename26 nvarchar(260) = NULL
, @filename27 nvarchar(260) = NULL
, @filename28 nvarchar(260) = NULL
, @filename29 nvarchar(260) = NULL
, @filename30 nvarchar(260) = NULL
, @filename31 nvarchar(260) = NULL
, @filename32 nvarchar(260) = NULL
as
declare @execstring nvarchar (4000)
set nocount on IF ((@dbname is null OR datalength(@dbname) = 0) OR
(@filename1 is null OR datalength(@filename1) = 0))
begin
raiserror (15004,-1,-1)
return (1)
end -- build initial CREATE DATABASE
select @execstring = 'CREATE DATABASE '
+ quotename( @dbname , '[')
+ ' ON (FILENAME ='
+ ''''
+ REPLACE(@filename1,N'''',N'''''')
+ '''' -- add any additional files if (@filename2 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename2 ,N'''',N'''''')
+ ''''
end if (@filename3 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename3 ,N'''',N'''''')
+ ''''
end if (@filename4 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename4 ,N'''',N'''''')
+ ''''
end if (@filename5 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename5 ,N'''',N'''''')
+ ''''
end if (@filename6 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename6 ,N'''',N'''''')
+ ''''
end if (@filename7 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename7 ,N'''',N'''''')
+ ''''
end if (@filename8 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename8 ,N'''',N'''''')
+ ''''
end if (@filename9 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename9 ,N'''',N'''''')
+ ''''
end if (@filename10 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename10 ,N'''',N'''''')
+ ''''
end if (@filename11 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename11 ,N'''',N'''''')
+ ''''
end if (@filename12 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename12 ,N'''',N'''''')
+ ''''
end if (@filename13 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename13 ,N'''',N'''''')
+ ''''
end if (@filename14 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename14 ,N'''',N'''''')
+ ''''
end if (@filename15 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename15 ,N'''',N'''''')
+ ''''
end if (@filename16 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename16 ,N'''',N'''''')
+ ''''
end
if (@filename17 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename17 ,N'''',N'''''')
+ ''''
end if (@filename18 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename18 ,N'''',N'''''')
+ ''''
end if (@filename19 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename19 ,N'''',N'''''')
+ ''''
end if (@filename20 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename20 ,N'''',N'''''')
+ ''''
end if (@filename21 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename21 ,N'''',N'''''')
+ ''''
end if (@filename22 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename22 ,N'''',N'''''')
+ ''''
end if (@filename23 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename23 ,N'''',N'''''')
+ ''''
end if (@filename24 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename24 ,N'''',N'''''')
+ ''''
end if (@filename25 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename25 ,N'''',N'''''')
+ ''''
end if (@filename26 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename26 ,N'''',N'''''')
+ ''''
end if (@filename27 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename27 ,N'''',N'''''')
+ ''''
end if (@filename28 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename28 ,N'''',N'''''')
+ ''''
end if (@filename29 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename29 ,N'''',N'''''')
+ ''''
end if (@filename30 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename30 ,N'''',N'''''')
+ ''''
end if (@filename31 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename31 ,N'''',N'''''')
+ ''''
end if (@filename32 IS NOT NULL)
begin
select @execstring = @execstring
+ ' ), (FILENAME= '''
+ REPLACE(@filename32 ,N'''',N'''''')
+ ''''
end -- note it as for attach
select @execstring = @execstring + ' ) FOR ATTACH'
exec (@execstring)if @@error <> 0
begin
-- No need to raiserror as the CREATE DATABASE will do so
return(1)
end
return (0) -- sp_attach_db