FM.SQL.InsertRecords
--------------------

Inserts records in FileMaker database from records in memory.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [FM](component_FM.md) [FMSQL](component_FMSQL.md) | [6.4](newinversion64.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "FM.SQL.InsertRecords"; SQLref; InsertFileName; InsertTableName; FieldNames { ; StartRow; EndRow } ) 

**MBS**( **"FM.SQL.InsertRecords";** /\* Inserts records in FileMaker database from records in memory. \*/  
**$SQLref**; /\* The reference number returned by [FM.SQL.Execute](FMSQLExecute.md) function. \*/   
**$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 [FM.SQL.RowCount](FMSQLRowCount.md)-1.e.g. 0 \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| SQLref | The reference number returned by [FM.SQL.Execute](FMSQLExecute.md) function. | $SQLRef |  |
| 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 [FM.SQL.RowCount](FMSQLRowCount.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).  
  
Please don't overload the function, so better work in blocks of e.g. 1000 rows at a time.  
### Examples

Copy records:

 # select some data   
Set Variable \[$Records ; Value:MBS ( "[FM.SQL.Execute](FMSQLExecute.md)"; ""; "SELECT FirstName, LastName, Birthday FROM test" )\]  
\# now insert them somewhere else   
Set Variable \[$r ; Value:MBS ( "FM.SQL.InsertRecords"; $Records ; ""; "test"; "FirstName¶LastName¶BirthDay")\]  
\# and free record set   
Set Variable \[$r ; Value:MBS ( "[FM.SQL.Release](FMSQLRelease.md)"; $Records )\]  
### See also

- [FM.ExecuteSQL.LastError](FMExecuteSQLLastError.md)
- [FM.ExecuteSQL.LastErrorMessage](FMExecuteSQLLastErrorMessage.md)
- [FM.SQL.Execute](FMSQLExecute.md)
- [FM.SQL.Release](FMSQLRelease.md)
- [FM.SQL.RowCount](FMSQLRowCount.md)
- [JSON.InsertRecords](JSONInsertRecords.md)
- [SQL.Execute](SQLExecute.md)
- [SQL.InsertOrUpdateRecords](SQLInsertOrUpdateRecords.md)
- [SQL.InsertRecords](SQLInsertRecords.md)
- [XML.InsertRecords](XMLInsertRecords.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 16.0**
    - Changed [FM.SQL.InsertRecordsToSQL](https://www.mbsplugins.eu/FMSQLInsertRecordsToSQL.shtml) and related functions to use backtick to quote table names for ODBC connections.
- **Version 14.2**
    - Fixed a bug in [FM.SQL.InsertRecords](https://www.mbsplugins.eu/FMSQLInsertRecords.shtml) that prevented containers from being transferred.
- **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 7.2**
    - Changed [FM.SQL.InsertRecordsToSQL](http://www.mbsplugins.eu/FMSQLInsertRecordsToSQL.shtml) to no longer quote by default.

### 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#2Button21.0000000204.000000052.0000000582.0000000LayoutObjectAnchor_)

### 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 14.2pr5](https://www.mbsplugins.de/archive/2024-05-08/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)
- [Query FileMaker records as JSON](https://www.mbsplugins.de/archive/2020-04-03/Query_FileMaker_records_as_JSO/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin 6.4 for OS X/Windows](https://www.mbsplugins.de/archive/2016-09-27/MBS_FileMaker_Plugin_64_for_OS/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 6.4pr3](https://www.mbsplugins.de/archive/2016-08-08/MBS_FileMaker_Plugin_version_6/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 3/2018, Seite 34](https://filemaker-magazin.de/neuigkeit/3953-Appetithappen-FMM_201803)

This function checks for a license.

Created 1st August 2016 , last changed 15th October 2021

  
[FM.SQL.InsertOrUpdateRecordsToSQL](FMSQLInsertOrUpdateRecordsToSQL.md) - [FM.SQL.InsertRecordsToSQL](FMSQLInsertRecordsToSQL.md)

[HTML Version](FMSQLInsertRecords.shtml)