Created
June 11, 2014 02:38
-
-
Save mrbusche/5da432a486962f8b9b1c to your computer and use it in GitHub Desktop.
Batch insert records to a database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
totalrows = 5000; // this would come from a structCount or something similar | |
rowsPerInsert = 210; | |
//this creates a struct with alternating values of true/false for test purposes | |
stRows = {}; | |
for(i=1; i<=totalRows; i++) { | |
stRows[i] = i MOD 2 ? true : false; | |
} | |
</cfscript> | |
<cfoutput> | |
<cfloop from="0" to="#totalRows - 1#" step="#rowsPerInsert#" index="totalRow"> | |
<br><br>INSERT #totalRow#<br> | |
<cfloop from="1" to="#rowsPerInsert#" index="indRow"> | |
<cfset rowNumber = totalRow + indRow> | |
<cfif rowNumber LTE totalRows> | |
#rowNumber# #stRows[rowNumber]# | |
<cfif indRow NEQ rowsPerInsert AND rowNumber NEQ totalRows> UNION ALL</cfif> | |
<br> | |
</cfif> | |
</cfloop> | |
</cfloop> | |
</cfoutput> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment