Is there a faster alternative to INSERT and FASTINSERT functions in the Database Toolbox 3.1 (R14SP3)?

2 views (last 30 days)
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
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;

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R14SP1

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!