FM.SQL.InsertOrUpdateRecordsToSQL
---------------------------------

Insert or updates a lot of records queried from a database.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [FM](component_FM.md) | [16.1](newinversion161.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "FM.SQL.InsertOrUpdateRecordsToSQL"; SQLref; Connection; InsertTableName; FieldNames; KeyFieldMapping ) 

**MBS**( **"FM.SQL.InsertOrUpdateRecordsToSQL";** /\* Insert or updates a lot of records queried from a database. \*/  
**$SQLref**; /\* The reference number returned by [FM.SQL.Execute](FMSQLExecute.md) function. \*/   
**$Connection**; /\* The connection reference number gained with [SQL.NewConnection](SQLNewConnection.md). \*/   
**$InsertTableName**; /\* The name of the table to insert record into.  
Can be ID of table, so we lookup name by ID.   
Can be result of GetFieldName() function as we remove field name automatically.e.g. "Assets" \*/   
**$FieldNames**; /\* A list of field names for the insert.  
Empty entries in the list are ignored.  
  
Can be ID of field, so we lookup name by ID.   
Can be result of GetFieldName() function as we remove table name automatically.e.g. "Model" \*/   
**$KeyFieldMapping**) /\* The list of field names with index to map keys.  
Please specify a list of key name=key index.  
The key name is the name of the field in the insert table and the index gives zero-based position in result set from SELECT query in 6th parameter.  
  
Field order in source and destination does not need to be the same.e.g. ID=0 \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| SQLref | The reference number returned by [FM.SQL.Execute](FMSQLExecute.md) function. | $SQLRef |
| Connection | The connection reference number gained with [SQL.NewConnection](SQLNewConnection.md). | $Connection |
| InsertTableName | The name of the table to insert record into.   Can be ID of table, so we lookup name by ID.    Can be result of GetFieldName() function as we remove field name automatically. | "Assets" |
| FieldNames | A list of field names for the insert.   Empty entries in the list are ignored.      Can be ID of field, so we lookup name by ID.    Can be result of GetFieldName() function as we remove table name automatically. | "Model" |
| KeyFieldMapping | The list of field names with index to map keys.   Please specify a list of key name=key index.   The key name is the name of the field in the insert table and the index gives zero-based position in result set from SELECT query in 6th parameter.      Field order in source and destination does not need to be the same. | ID=0 |

### Result

Returns OK or error.

### Description

Insert or updates a lot of records queried from a database.  
Reports an error if field name list doesn't match column count of the stored SQL result.  
### Examples

Insert or update to SQL database:

 Set Variable \[ $InsertFields ; Value: "Key¶TextField¶NumberField¶DateField¶TimeField¶TimestampField¶ContainerField¶Description" \]  
Set Variable \[ $result ; Value: MBS ("FM.SQL.InsertOrUpdateRecordsToSQL"; $sql ; $Connection ; "Test"; $InsertFields ; "Key=0") \]  
### See also

- [FM.SQL.Execute](FMSQLExecute.md)
- [FM.SQL.InsertOrUpdateRecords](FMSQLInsertOrUpdateRecords.md)
- [Matrix.InsertOrUpdateRecordsToSQL](MatrixInsertOrUpdateRecordsToSQL.md)
- [SQL.Execute](SQLExecute.md)
- [SQL.InsertOrUpdateRecords](SQLInsertOrUpdateRecords.md)
- [SQL.NewConnection](SQLNewConnection.md)

### Release notes

- **Version 16.1**
    - Added [FM.SQL.InsertOrUpdateRecordsToSQL](https://www.mbsplugins.eu/FMSQLInsertOrUpdateRecordsToSQL.shtml) and [Matrix.InsertOrUpdateRecordsToSQL](https://www.mbsplugins.eu/MatrixInsertOrUpdateRecordsToSQL.shtml) functions.

### Example Databases

- [SQL in FileMaker/Insert or Update Tests](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/SQL%20in%20FileMaker/Insert%20or%20Update%20Tests.shtml#16ScriptAnchor_)

### Blog Entries

- [MBS FileMaker Plugin 16.1 News](https://www.mbsplugins.de/archive/2026-03-31/MBS_FileMaker_Plugin_161_News/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 16.1pr1](https://www.mbsplugins.de/archive/2026-02-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 27th January 2026 , last changed 12nd February 2026

  
[FM.SQL.InsertOrUpdateRecords](FMSQLInsertOrUpdateRecords.md) - [FM.SQL.InsertRecords](FMSQLInsertRecords.md)

[HTML Version](FMSQLInsertOrUpdateRecordsToSQL.shtml)