Hi,
What is the best instruction in other to copy one TABLE from one MS SQL database to another on another MS SQL SERVER ?
Thanks for your samples .
Philippe
SELECT * INTO NewTable FROM OldTable
insert into newTable select * from oldTable
insert into newTable (a,b,c) select a,b,c from oldTable
SELECT * INTO dbDest.dbo.NewTable FROM dbSrc.dbo.OldTable
#include "fivewin.ch"
function Main()
local oLocal := FW_OpenAdoConnection( "MSSQL,SQLEXPRESS,FWH", .t. )
local oCloud := FW_MSSQLDB()
local oRs, aRows, aStruct, cCol, cVal, cTable, cSql
local lIdentityInsert := .f.
local nBatch := 100
? "Open Local Table"
cTable := "customer"
oRs := FW_OpenRecordSet( oLocal, "SELECT * FROM [" + cTable + "]" )
aStruct := FWAdoStruct( oRs )
lIdentityInsert := ( AScan( aStruct, { |a| a[ 2 ] == "+" } ) > 0 )
cCol := "( " + FW_QuotedColSQL( FW_ArrayAsList( ArrTranspose( aStruct )[ 1 ] ) ) + " )"
? "Write to cloud server"
FWAdoCreateTable( "#" + cTable, aStruct, oCloud )
cSql := "INSERT INTO [#" + cTable + "] " + cCol + " VALUES "
if lIdentityInsert
oCloud:Execute( "SET IDENTITY_INSERT [#" + cTable + "] ON" )
endif
oRs:MoveFirst()
do while !oRs:Eof()
aRows := oRs:GetRows( nBatch )
if HarbourNew()
aRows := ArrTransposeQ( aRows )
endif
cVal := FW_ValToSQL( aRows )
cVal := SubStr( cVal, 2, Len( cVal ) - 2 )
oCloud:Execute( cSql + cVal )
SysRefresh()
enddo
oRs:MoveFirst()
oRs:Close()
if lIdentityInsert
oCloud:Execute( "SET IDENTITY_INSERT [#" + cTable + "] OFF" )
endif
? "Verify"
oRs := FW_OpenRecordSet( oCloud, "SELECT * FROM [#" + cTable + "]" )
XBROWSER oRs
oRs:Close()
oCloud:Close()
oLocal:Close()
return nil
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 103 guests