{"title":"Bulk Inserts","url":"https://jonas-paprotka.de/docs/dev-itpro/administration/optimize-sql-bulk-inserts/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/administration/optimize-sql-bulk-inserts, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/administration/optimize-sql-bulk-inserts","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Learn how to optimize SQL bulk inserts in Business Central for improved performance and scalability. Understand constraints and disabling bulk inserts.","date":"2021-04-01","meta":{"topic":"how-to"},"outline":[{"level":2,"title":"Bulk Insert Constraints","slug":"bulk-insert-constraints","at":578,"chars":1591},{"level":2,"title":"Disabling Bulk Inserts","slug":"disabling-bulk-inserts","at":2169,"chars":349},{"level":2,"title":"Related information","slug":"related-information","at":2518,"chars":189}],"text":"By default, Business Central automatically buffers inserts in order to send them to Microsoft SQL Server at one time.\nBy using bulk inserts, the number of server calls is reduced, thereby improving performance.\nBulk inserts also improve scalability by delaying the actual insert until the last possible moment in the transaction. This reduces the amount of time that tables are locked; especially tables that contain SIFT indexes.\nApplication developers who want to write high performance code that utilizes this feature should understand the following bulk insert constraints.\n## Bulk Insert Constraints\nIf you want to write code that uses the bulk insert functionality, you must be aware of the following constraints.\nRecords are sent to SQL Server when the following occurs:\n You call COMMIT to commit the transaction.\n You call MODIFY or DELETE on the table.\n You call any FIND or CALC methods on the table.\n  Records are not buffered if any of the following conditions are met:\n The application is using the return value from an INSERT call; for example, \"`IF (GLEntry.INSERT) THEN`\".\n The table that you are going to insert the records into contains any of the following:\n   BLOB fields\n   Fields with the AutoIncrement property set to True\n  The following code example cannot use buffered inserts because it contains a FIND call on the GL/Entry table within the loop.\n```\nIF (JnlLine.FIND('-')) THEN BEGIN\n  GLEntry.LOCKTABLE;\n  REPEAT\n    IF (GLEntry.FINDLAST) THEN\n      GLEntry.NEXT := GLEntry.\"Entry No.\" + 1\n    ELSE\n      GLEntry.NEXT := 1;\n    // The FIND call will flush the buffered records.\n    GLEntry.\"Entry No.\" := GLEntry.NEXT ;\n    GLEntry.INSERT;\n  UNTIL (JnlLine.FIND('>') = 0)\nEND;\nCOMMIT;\n```\nIf you rewrite the code, as shown in the following example, you can use buffered inserts.\n```\nIF (JnlLine.FIND('-')) THEN BEGIN\n  GLEntry.LOCKTABLE;\n  IF (GLEntry.FINDLAST) THEN\n    GLEntry.Next := GLEntry.\"Entry No.\" + 1\n  ELSE\n    GLEntry.Next := 1;\n  REPEAT\n    GLEntry.\"Entry No.\":= GLEntry.Next;\n    GLEntry.Next := GLEntry.\"Entry No.\" + 1;\n    GLEntry.INSERT;\n  UNTIL (JnlLine.FIND('>') = 0)\nEND;\nCOMMIT;\n// The inserts are performed here.\n```\n## Disabling Bulk Inserts\nDisabling bulk inserts can be helpful when you are troubleshooting failures that occur when inserting records. To disable bulk inserts, you set the BufferedInsertEnabled parameter in the CustomSettings.config file of the Business Central Server to FALSE. See Configuring Business Central Server<configure-server-instance>.\n## Related information\noptimize-sql-data-access\noptimize-sql-table-keys-and-performance\noptimize-sql-al-database-methods-and-performance-on-server\noptimize-sql-query-objects-and-performance"}