Logging Multiple Records with NJDB BatchInsert
What is DB_BatchInsert
Structure data is temporarily stored in the ring buffer
When inserting into the database, data is read from the ring buffer and the DB_BatchInsert instruction is executed
DB_BatchInsert inserts multiple records at once, so reading multiple data items accumulated in the ring buffer and batch-inserting them into the DB is expected to shorten insertion time

Differences from DB_Insert
| Method | Characteristics |
|---|---|
| DB_Insert | Adds one record at a time |
| DB_BatchInsert | Adds multiple records at once |
DB_BatchInsert is suited to saving large amounts of data. It reduces the number of communications, lowering database load.
Benefits of DB_BatchInsert
- Fewer communications
- Fast saving of large amounts of data
- Lower database load
- Suited to long-term logging
Functions used
Uses the ring buffer functions


Structure for logging

Ladder program example

If there are records in the ring buffer, connects to the DB
Maps the structure to the DB table and sets the data accumulated in the ring buffer into the structure
Here up to 1000 records are inserted at a time
Executes the DB_BatchInsert instruction and closes
FAQ
Which is faster, DB_Insert or DB_BatchInsert?
For large amounts of data, DB_BatchInsert is faster. It reduces the number of communications, lowering processing load.
How many records can be registered at once?
It depends on PLC memory capacity and database settings. The sample uses a limit of 1000 records.
Is a ring buffer required?
It is not required, but it is recommended because it separates fast collection from DB communication.
