Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Updating SQL Server table
Message
De
09/03/2005 12:10:14
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
09/03/2005 10:54:10
Jerry Tovar
Dana Corporation Dana It
Maumee, Ohio, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 8 SP1
Database:
MS SQL Server
Divers
Thread ID:
00994024
Message ID:
00994067
Vues:
27
>I need to insert 400,000 records from a VFP8 table into a Sql Server table nightly.
>
>I have created an updatable remote view in my VFP DBC to this SQL Server table. I then update the Sql Server table as follows.
>
>***
>USE myRemoteView IN 0
>USE myvfptable IN 0
>SELECT myvfptable
>SCAN
>   SCATTER MEMVAR
>   INSERT INTO myRemoteView FROM MEMVAR
>ENDSCAN
>***
>
>
>All this works, but it takes a long time to complete. Is there a faster way to run this process? How can I speed this up>
>
>Thanks,
>
>Jerry

1) If you use an updatable RV or SPT set buffering to 5.
2) You can use "copy to myTransfer.txt type delimited" and bulk insert
3) You can use DTS package
4) You can use OpenRowSet() SQL server function

Last one is one of the fastest I think. Below is partial class I've used for my own upsizing (fieldnames were same):
* Sample
oTransfer = CreateObject("SQLPutData")
oTransfer.PutTheData()

Define Class SQLPutData As Session
	DataSession=2
	DBPATH = Sys(5)+Curdir()+'myLocalDatabasePath'
        LocalDBC = 'myLocalDatabase.dbc'
	SQLDBNAME = "mySQLDatabase"
	conHandle = .Null.

	Procedure Init
		This.conHandle = ;
                Sqlstringconnect("Driver=SQL server;server=(local);Integrated Security=SSPI")
		SQLExec(This.conHandle,"use ["+This.SQLDBNAME+"]")
	Endproc

	Procedure PutTheData
		With This
                   .GetDataFrom("[dbo].[mytable]","[field1],[field2],[field3]")
                   SQLDisconnect(.conHandle)
                endwith
        endproc

	Procedure GetDataFrom
		Lparameters tcSQLName,tcFields
		Local lcLocalTable, lcLocalFields, lcSQL, lnResult, ix, lcError
		Local array arrErr[1]
		lcLocalTable  = Justext(Chrtran(tcSQLName,'[]',''))
		lcLocalFields = Chrtran(tcFields,'[]','')
		Text to m.lcSQL textmerge noshow
		insert into <<m.tcSQLName>>
			SELECT <<m.tcFields>>
			FROM OPENROWSET('VFPOLEDB',
			'<<Addbs(this.DBPATH)+this.LocalDBC>>';'';'',
			'select <<m.lcLocalFields>> from <<m.lcLocalTable>>')
		endtext
		lnResult = SQLExec(this.conHandle, m.lcSQL)
		If m.lnResult < 0
			AError(arrErr)
			lcError = ''
			For ix = 1 to Alen(arrErr)
				lcError = lcError + Transform(arrErr[m.ix]) + Chr(13)	 
			EndFor
			MessageBox(m.lcError)
		Else
			? m.tcSQLName
		endif
	Endproc
enddefine
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform