Matrix.InsertRecords
--------------------

Inserts records in FileMaker database from records in memory.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [Matrix](component_Matrix.md) | [9.2](newinversion92.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "Matrix.InsertRecords"; MatrixRef; InsertFileName; InsertTableName; FieldNames { ; StartRow; EndRow } ) 

**MBS**( **"Matrix.InsertRecords";** /\* Inserts records in FileMaker database from records in memory. \*/  
**$MatrixRef**; /\* The matrix reference number.e.g. $matrix \*/   
**$InsertFileName**; /\* The file name of where the insert table is inside. Can be empty to look for the table in all files.e.g. Get(FileName) \*/   
**$InsertTableName**; /\* The name of the table to insert record into.e.g. "Assets" \*/   
**$FieldNames**; /\* A list of field names for the insert.   
Empty entries in the list are ignored.e.g. "Model" \*/   
**$StartRow**; /\* Optional; The index of the start row in the current recordset.  
First row is 0.e.g. 0 \*/   
**$EndRow**) /\* Optional; The index of the end row in the current recordset.  
First row is 0. Last Row would be [Matrix.Height](MatrixHeight.md)-1.e.g. 0 \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| MatrixRef | The matrix reference number. | $matrix |  |
| InsertFileName | The file name of where the insert table is inside. Can be empty to look for the table in all files. | Get(FileName) |  |
| InsertTableName | The name of the table to insert record into. | "Assets" |  |
| FieldNames | A list of field names for the insert.    Empty entries in the list are ignored. | "Model" |  |
| StartRow | The index of the start row in the current recordset.   First row is 0. | 0 | Optional |
| EndRow | The index of the end row in the current recordset.   First row is 0. Last Row would be [Matrix.Height](MatrixHeight.md)-1. | 0 | Optional |

### Result

Returns OK or error.

### Description

Inserts records in FileMaker database from records in memory.  
This function allows to easily copy a lot of records from a query in FileMaker database into a FileMaker table.  
Please provide field names in FileMaker. The order has to match those in the record set.  
Due to passing in new field names, you can even rearrange values from one column to other while copying. In the SQL you can use functions for sums or join data from several tables together to fill a new table.   
Use [FM.ExecuteSQL.LastErrorMessage](FMExecuteSQLLastErrorMessage.md) and [FM.ExecuteSQL.LastError](FMExecuteSQLLastError.md) to see error message.  
Reports an error if field name list doesn't match column count of the query result.  
Function will fail if data types in source and dest fields do not match for assignment. e.g. date and time fields will not work, only timestamp fields.  
  
For insert from SQL Connection into FileMaker database, please use [SQL.InsertRecords](SQLInsertRecords.md).  
### See also

- [FM.ExecuteSQL](FMExecuteSQL.md)
- [FM.ExecuteSQL.LastError](FMExecuteSQLLastError.md)
- [FM.ExecuteSQL.LastErrorMessage](FMExecuteSQLLastErrorMessage.md)
- [Matrix.Height](MatrixHeight.md)
- [Matrix.InsertRecordsToSQL](MatrixInsertRecordsToSQL.md)
- [SQL.InsertRecords](SQLInsertRecords.md)
- [XL.Sheet.ReadCellsAsMatrix](XLSheetReadCellsAsMatrix.md)

### Release notes

- **Version 16.1**
    - Improved [Matrix.InsertRecordsToSQL](https://www.mbsplugins.eu/MatrixInsertRecordsToSQL.shtml) and [FM.SQL.InsertRecordsToSQL](https://www.mbsplugins.eu/FMSQLInsertRecordsToSQL.shtml) functions to pass NULL if a number or date field is empty. Otherwise SQL would complain about passing invalid date or number.
    - Rewrote [FM.SQL.InsertRecords](https://www.mbsplugins.eu/FMSQLInsertRecords.shtml) and [Matrix.InsertRecords](https://www.mbsplugins.eu/MatrixInsertRecords.shtml) functions to use same code internal.
    - Rewrote [FM.SQL.InsertRecordsToSQL](https://www.mbsplugins.eu/FMSQLInsertRecordsToSQL.shtml) and [Matrix.InsertRecordsToSQL](https://www.mbsplugins.eu/MatrixInsertRecordsToSQL.shtml) functions to use same code internal.
- **Version 13.2**
    - Changed field quoting for [FM.SQL.InsertRecordsToSQL](https://www.mbsplugins.eu/FMSQLInsertRecordsToSQL.shtml) and [Matrix.InsertRecordsToSQL](https://www.mbsplugins.eu/MatrixInsertRecordsToSQL.shtml) to handle non ANSI quotes for MySQL/MariaDB.
- **Version 13.1**
    - Fixed [FM.SQL.InsertRecords](https://www.mbsplugins.eu/FMSQLInsertRecords.shtml), [FM.SQL.InsertRecordsToSQL](https://www.mbsplugins.eu/FMSQLInsertRecordsToSQL.shtml), [Matrix.InsertRecordsToSQL](https://www.mbsplugins.eu/MatrixInsertRecordsToSQL.shtml) and [Matrix.InsertRecords](https://www.mbsplugins.eu/MatrixInsertRecords.shtml) to quote the table name for the SQL used internally.
- **Version 11.0**
    - Enhanced [Matrix.InsertRecords](https://www.mbsplugins.eu/MatrixInsertRecords.shtml) to detect field data type and pass numbers and date/time/timestamp to FileMaker.

### 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#2Button67.0000000204.000000098.0000000582.0000000LayoutObjectAnchor_)
- [SQL to other databases/SQLite fun](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/SQL%20to%20other%20databases/SQLite%20fun.shtml#13ScriptAnchor_)

### Blog Entries

- [MBS FileMaker Plugin, version 16.1pr1](https://www.mbsplugins.de/archive/2026-02-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 13.1pr1](https://www.mbsplugins.de/archive/2023-02-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [CSV in FileMaker with MBS FileMaker Plugin](https://www.mbsplugins.de/archive/2022-10-11/CSV_in_FileMaker_with_MBS_File/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 10.6pr1](https://www.mbsplugins.de/archive/2020-12-02/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [Import CSV with Matrix functions](https://www.mbsplugins.de/archive/2020-11-20/Import_CSV_with_Matrix_functio/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 8th April 2019 , last changed 7th April 2022

  
[Matrix.InsertOrUpdateRecordsToSQL](MatrixInsertOrUpdateRecordsToSQL.md) - [Matrix.InsertRecordsToSQL](MatrixInsertRecordsToSQL.md)

[HTML Version](MatrixInsertRecords.shtml)