{"title":"Temporary tables","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/devenv-temporary-tables/","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/developer/devenv-temporary-tables, 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/developer/devenv-temporary-tables","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 about temporary tables in AL for Business Central.","date":"2026-06-24","meta":{"topic":"article"},"outline":[{"level":2,"title":"Advantage of using a temporary table","slug":"advantage-of-using-a-temporary-table","at":624,"chars":702},{"level":2,"title":"Creating and using a temporary table","slug":"creating-and-using-a-temporary-table","at":1326,"chars":578},{"level":2,"title":"Setting the TableType to Temporary","slug":"setting-the-tabletype-to-temporary","at":1904,"chars":1340},{"level":3,"title":"Change the table type","slug":"change-the-table-type","at":2774,"chars":470},{"level":2,"title":"Use a temporary record variable","slug":"use-a-temporary-record-variable","at":3244,"chars":690},{"level":2,"title":"Use a SourceTableTemporary property on page objects","slug":"use-a-sourcetabletemporary-property-on-page-objects","at":3934,"chars":449},{"level":2,"title":"Permissions and temporary tables","slug":"permissions-and-temporary-tables","at":4383,"chars":943},{"level":2,"title":"Temporary tables on reports and XMLPorts","slug":"temporary-tables-on-reports-and-xmlports","at":5326,"chars":969},{"level":2,"title":"Related information","slug":"related-information","at":6295,"chars":226}],"text":"A temporary table is a temporary variable that holds a table. A temporary table is used as a buffer or intermediate storage for table data.\nYou can use a temporary table just like you use a database table. The differences between a temporary table and a database table are as follows:\n A temporary table data isn't stored in the database. It's only held in memory until the table is closed.\n The write transaction principle that applies to a database table doesn't apply to a temporary table.\n> TIP\n> IntelliSense, tooltips, and CodeLens displays a suffix after the table name to indicate when a table is a temporary table.\n## Advantage of using a temporary table\nThe advantage of using a temporary table is that the interaction with a temporary table occurs on Dynamics 365 Business Central. A temporary table reduces the load on both the network and the SQL database server.\nWhen you want to do many operations on the data in a specific database table, you can load the data into a temporary table when you modify it. Loading the data into a temporary table speeds up the process because all the operations are done in memory on the Business Central Server.\nLearn more about endpoint performance and temporary tables in Anti-patterns (don't do this)<../performance/performance-developer#general-anti-patterns-dont-do-this>.\n## Creating and using a temporary table\nThere are three ways to implement a temporary table:\n Setting the properties/devenv-tabletype-property on the table object to Temporary.\n Using a temporary record variable.\n Setting the properties/devenv-sourcetabletemporary-property on a page.\nWhichever way you choose, you must create the devenv-table-object that defines the fields, like any other table object. The differences are explained in the following sections.\n> TIP\n> Temporary tables retain system fields, like SystemID and data audit fields. See devenv-table-system-fields.\n## Setting the TableType to Temporary\nWith this implementation, a physical table isn't created in the database. In the table object, set the TableType property to Temporary:\n```al\ntable 50100 MyTable\n{\n    DataClassification = ToBeClassified;\n    TableType = Temporary;\n\n    fields\n\n    ...\n}\n```\nThis implementation has the same effect as using a temporary record variable or setting the SourceTableTemporary property on a page. But the advantage is that the table schema isn't synchronized with the database. So it doesn't have restrictions on breaking schema changes, like removing a field, changing its data type or length.\nIt also improves the performance of BACPAC generation using the sqlpackage command-line tool, compared to temporary tables based on temporary record variables and pages. See ../performance/performance-onprem#performance-of-bacpac-generation.\n### Change the table type\nYou can change from Normal to Temporary, and the other way around. When changing Normal to Temporary the table, you have to synchronize the extension with the database. This step removes the table from the database. So if the table contains data, you have to synchronize the schema using the ForceSync mode.\n> NOTE\n> Changing the table type is considered a destructive change. So this change can only be done with Business Central on-premises.\n## Use a temporary record variable\nWith this implementation, a physical table isn't created in the database. You create a global or local variable of the type record and set the Temporary Property<properties/devenv-properties> next to it. The variable that holds a temporary table is defined just like any other global or local variable. The syntax is shown in the following example:\n```al\nvar\n    TempInvoicePostBuffer: Record \"Invoice Post. Buffer\" temporary;\n```\nYou manipulate the temporary table variable as you would with any other database table. For example, you can apply filters and do searches. Learn more about the operations you can do in methods-auto/record/record-data-type.\n## Use a SourceTableTemporary property on page objects\nAnother option for temporary tables is to set the properties/devenv-sourcetabletemporary-property on all pages that use the table. This implementation also uses a physical table in the database.\n```al\npage 50100 MyPage\n{\n    PageType = Card;\n    ApplicationArea = All;\n    UsageCategory = Administration;\n    SourceTable = TableName;\n    SourceTableTemporary = true;\n\n    layout\n\n    ...\n}\n```\n## Permissions and temporary tables\nTemporary tables don't require the user to have permissions on the underlying table. Because temporary table data is held only in memory and never read from or written to the database, the permission system doesn't apply. A user can create, read, modify, and delete records in a temporary table even if they have no permissions defined for that table.\nThis behavior applies regardless of how the temporary table is implemented&mdash;whether by using the TableType property, a temporary record variable, or the SourceTableTemporary property on a page.\n```al\nprocedure DoWork()\nvar\n    TempItem: Record Item temporary;\nbegin\n    // No permissions on the Item table are required for these operations\n    TempItem.Init();\n    TempItem.\"No.\" := 'TEMP001';\n    TempItem.Description := 'Temporary item';\n    TempItem.Insert();\n\n    TempItem.Description := 'Updated temporary item';\n    TempItem.Modify();\nend;\n```\n## Temporary tables on reports and XMLPorts\nYou can also use temporary tables for storing the data set that's returned by a report object or imported by an XMLPort. To do so, set the UseTemporary property to true on the relevant report data item or XMLPort table element. See properties/devenv-usetemporary-xmlport-property and properties/devenv-usetemporary-report-property.\nTemporary tables are useful on reports when the column data isn't mapped directly to a field in the database. But instead, the data is a result of a process or operation. For example, suppose the column was an aggregation of data from several columns. If a temporary table isn't used, the data must be handled by AL code.\nFor XMLPorts, if the data that you're importing has a different structure than the table in Dynamics 365 Business Central that you want to insert it into, you can import the data into a temporary table. You can then modify the data before inserting it into the database.\n## Related information\nGet Started with AL<devenv-get-started>\ndevenv-table-object\nTemporary Property<properties/devenv-properties>\nproperties/devenv-usetemporary-report-property\nproperties/devenv-usetemporary-xmlport-property"}