Is there a faster alternative to INSERT and FASTINSERT functions in the Database Toolbox 3.1 (R14SP3)?
2 views (last 30 days)
Show older comments
I have a large dataset (~200,000 records) that I wish to insert into my database. Both INSERT and FASTINSERT seem to be too slow for this purpose.
Accepted Answer
MathWorks Support Team
on 23 Jun 2011
The approach illustrated in the example below can serve as a faster alternative to INSERT and FASTINSERT for very large datasets.
This approach requires the user to set up the SQL INSERT statements in an array. These statements can then be batch executed as illustrated below:
% sqlStrings contains several SQL INSERT statements of the form
% INSERT INTO BONUS (ENAME,JOB,SAL,COMM) VALUES ('Nomar', 'Shortstop', 1000000, 50)
connect = database('datasourcename', 'username', 'password');
connHandle = connect.Handle;
stmt = connHandle.createStatement;
for i = 1:size(sqlStrings,1)
stmt.addBatch(sqlStrings(i,:));
end
stmt.executeBatch;
stmt.close;
0 Comments
More Answers (0)
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!