Method for transferring data to be archived from a runtime database (RT_DB) into a long-term archive database (LTA_DB) in a Manufacturing Execution System, also known as MES system, wherein: - the runtime database (RT_DB) comprises a set of runtime tables, each runtime database table relating to a MES component and having a specific data structure, - the long-term archive database (LTA_DB) comprises a set of long-term archive tables, said set of long-term archive tables is mirroring the set of runtime tables, meaning that each long-term archive table has the same data structure of its corresponding runtime table; - according to specific archiving criteria, selecting a set of data records to be archived in the runtime database (RT_DB), the data archiving being performed by transferring the selected record set from a subset of runtime tables to their corresponding subset of long-term archive tables; the method characterized in that it comprises the following steps: a) providing an additional database, herein after referred as temporary database (TMP_DB) acting as buffer database for the selected data record set to be archived; b) for each table of said runtime table subset, creating a corresponding matching table in the temporary database (TMP_DB) so as to generate a set of temporary tables; c) copying (STc), for each table of the runtime table subset, the selected record subset to be archived into its corresponding table of the temporary table set in the temporary database (TMP_DB); d) copying (STd), for each table of the temporary table set, the selected record subset to be archived into its corresponding table of the long-term archive table subset in the long-term archive database (LTA_DB); e) if the copying of step d) is successful, creating (STe), for each table of the temporary table set, a temporary deletion table comprising a set of primary keys of the records to be deleted from the runtime database (RT_DB), said primary key set being extracted from the temporary table so as to generate a set of temporary deletion tables within the temporary database (TMP_DB); f) in the runtime database (RT_DB), for each runtime table having a corresponding temporary deletion table of the set of temporary deletion tables, deleting (STf) each record having primary key matching the primary key of the primary key set of its corresponding temporary table; - wherein steps c), d) and step e) are executed under a same transaction and wherein step f) is executed under another transaction. - the runtime database (RT_DB) comprises a set of runtime tables, each runtime database table relating to a MES component and having a specific data structure, - the long-term archive database (LTA_DB) comprises a set of long-term archive tables, said set of long-term archive tables is mirroring the set of runtime tables, meaning that each long-term archive table has the same data structure of its corresponding runtime table; - according to specific archiving criteria, selecting a set of data records to be archived in the runtime database (RT_DB), the data archiving being performed by transferring the selected record set from a subset of runtime tables to their corresponding subset of long-term archive tables; a) providing an additional database, herein after referred as temporary database (TMP_DB) acting as buffer database for the selected data record set to be archived; b) for each table of said runtime table subset, creating a corresponding matching table in the temporary database (TMP_DB) so as to generate a set of temporary tables; c) copying (STc), for each table of the runtime table subset, the selected record subset to be archived into its corresponding table of the temporary table set in the temporary database (TMP_DB); d) copying (STd), for each table of the temporary table set, the selected record subset to be archived into its corresponding table of the long-term archive table subset in the long-term archive database (LTA_DB); e) if the copying of step d) is successful, creating (STe), for each table of the temporary table set, a temporary deletion table comprising a set of primary keys of the records to be deleted from the runtime database (RT_DB), said primary key set being extracted from the temporary table so as to generate a set of temporary deletion tables within the temporary database (TMP_DB); f) in the runtime database (RT_DB), for each runtime table having a corresponding temporary deletion table of the set of temporary deletion tables, deleting (STf) each record having primary key matching the primary key of the primary key set of its corresponding temporary table; - wherein steps c), d) and step e) are executed under a same transaction and wherein step f) is executed under another transaction.