환경 : SQL Server 2008 R2.
다음은 데이터베이스에서 테이블 세트의 데이터를 동일한 스키마를 가진 다른 데이터베이스로 복사하기 위해 APP에서 호출하는 저장 프로 시저입니다. 데이터를 복사하지 않는 것 같습니다. 쿼리 분석기에서 수동으로 실행하려고 할 때.
exec dbo.sp_Copy_DB_Subset_Tables ('Server1\Instance','MainDB','Server1\Instance','MiniDB')
하지만 실행할 때이 오류가 발생합니다.
메시지 102, 수준 15, 상태 1, 줄 1
'Server1 \ Instance'근처에 잘못된 구문이 있습니다.
여기에 저장 프로 시저가 있습니다. 어떻게 오류가 발생하는지 알 수 없습니다. 데이터베이스는 동일한 서버에 있습니다. 왜 오류가 발생합니까?
CREATE PROCEDURE [dbo].[sp_Copy_MYDB_Subset_Tables](
@vSourceServer varchar(255)
,@vSourceDatabase varchar(255) = 'MYDB'
,@vDestinationServer varchar(255)
,@vDestinationDatabase varchar(255) = 'MYDB'
,@vIsServerOnDomain BIT = 1 --
,@TargetDBUserName varchar(255) = ''
,@TargetDBPassword varchar(255) = ''
)
AS
BEGIN
Declare
@vSourceTable varchar(255)
,@vSourceSelectQuery varchar(255)
,@vDestinationTable varchar(255)
,@vReturn int
,@vReturnMessage varchar(max)
,@vPeriodtoArchive int
,@ColumnMappings varchar(4000)
BEGIN TRY
if (@vSourceServer is null or @vSourceServer = '')
set @vSourceServer = @@servername
if object_id('tempdb..#TempTableCopyList') is not null
drop table #TempTableCopyList
Create Table #TempTableCopyList
(
id [int] NOT NULL primary key clustered
,TableName varchar(100)
,ColumnMappings varchar(4000)
,DateCopied datetime
)
insert into #TempTableCopyList
Select id, TableName, ColumnMappings, DateCopied
from dbo.fn_Get_MYDB_Subset_TableList()
declare c cursor for
Select TableName, ColumnMappings
from #TempTableCopyList
order by id desc
open c
fetch next from c into @vSourceTable, @ColumnMappings
While @@fetch_status = 0
BEGIN
print 'Start Copying table: ' + @vSourceTable + ' at ' + convert(varchar(30),getdate(),120)
Set @vSourceSelectQuery = 'Select * from ' + @vSourceTable + ' with (nolock) '
IF @vIsServerOnDomain = 0
BEGIN
exec master.dbo.usp_BulkCopy
@vSourceServer
,@vSourceDatabase
,@vSourceSelectQuery
,@vDestinationServer
,@vDestinationDatabase
,@vSourceTable
,1
,1
,true
,false
,''
,''
,@TargetDBUserName
,@TargetDBPassword
,@ColumnMappings
END
ELSE BEGIN
exec master.dbo.usp_BulkCopy
@vSourceServer
,@vSourceDatabase
,@vSourceSelectQuery
,@vDestinationServer
,@vDestinationDatabase
,@vSourceTable
,1
,1
,true
,true
,''
,''
,''
,''
,@ColumnMappings
END
UPDATE #TempTableCopyList
set DateCopied = GETDATE()
WHERE TableName = @vSourceTable
fetch next from c into @vSourceTable, @ColumnMappings
END
close c
deallocate c
END TRY
BEGIN CATCH
close c
deallocate c
DECLARE @ErrorMessage VARCHAR(MAX)
SET @ErrorMessage = error_message()
print @vSourceTable + '; '+ @vSourceServer+ '; '+ @vSourceDatabase+ '; '+ @vDestinationServer+ '; '+ @vDestinationDatabase+ '; '+ @vDestinationTable
Print @ErrorMessage
RAISERROR (@ErrorMessage, 0, 1)
END CATCH
--INFORMATIONAL
SELECT * FROM #TempTableCopyList
drop table #TempTableCopyList
return
END
exec dbo.sp_Copy_DB_Subset_Tables 'Server1\Instance','MainDB','Server1\Instance','MiniDB'
괄호없이 사용해 보시겠습니까?
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다