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

Creates records in FileMaker database for current recordset.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [SQL](component_SQL.md) | [5.2](newinversion52.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "SQL.InsertRecords"; Command; InsertFileName; InsertTableName; FieldNames { ; IgnoreDuplicates } ) 

**MBS**( **"SQL.InsertRecords";** /\* Creates records in FileMaker database for current recordset. \*/  
**$Command**; /\* The command reference number gained with [SQL.NewCommand](SQLNewCommand.md). \*/   
**$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" \*/   
**$IgnoreDuplicates**) /\* Optional; If 1, ignores duplicates or with 0 or by default reports error for duplicates.  
If duplicates are found, the function returns number of duplicates instead of OK.e.g. 0 \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| Command | The command reference number gained with [SQL.NewCommand](SQLNewCommand.md). | $Command |  |
| 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" |  |
| IgnoreDuplicates | If 1, ignores duplicates or with 0 or by default reports error for duplicates.   If duplicates are found, the function returns number of duplicates instead of OK. | 0 | Optional      Added in version **7.3**. |

### Result

Returns number of duplicates, OK or error.

### Description

Creates records in FileMaker database for current recordset.  
This function allows to easily copy a lot of records from SQL database into 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.  
This will not work for BLOBs as they are stored currently as hex encoded text only.  
Function will fail if data types in FileMaker and other SQL database do not match for assignment. e.g. date and time fields will not work, only timestamp fields.  
  
For copying record within FileMaker, please use [FM.InsertRecordQuery](FMInsertRecordQuery.md) or [FM.SQL.InsertRecords](FMSQLInsertRecords.md) functions.  
  
Please don't overload the function, so better work in blocks of e.g. 1000 rows at a time.  
### Examples

Insert records to FileMaker from SQL database:

 #Create select command and run it   
Set Variable \[$Command ; Value:MBS ("[SQL.NewCommand](SQLNewCommand.md)"; $Connection ; "SELECT FirstName, LastName, Birthday, NumberOfOrders, TotalSales FROM Test")\]  
\#Run it   
Set Variable \[$result ; Value:MBS ("[SQL.Execute](SQLExecute.md)"; $Command )\]  
If \[$result ≠ "OK"\]  
 Show Custom Dialog \["Error: " &amp; $result \]  
Else  
 Set Variable \[$result ; Value:MBS ("SQL.InsertRecords"; $Command ; Get(FileName) ;"SQLite fun"; "FirstName¶LastName¶Birthday¶NumberOfOrders¶TotalSales")\]  
 Show Custom Dialog \["Records imported."; $result \]  
End If  
\#Cleanup   
Set Variable \[$result2 ; Value:MBS ("[SQL.FreeCommand](SQLFreeCommand.md)"; $Command )\]  
### See also

- [FM.InsertRecord](FMInsertRecord.md)
- [FM.InsertRecordQuery](FMInsertRecordQuery.md)
- [FM.InsertRecordQueryIgnoreDuplicates](FMInsertRecordQueryIgnoreDuplicates.md)
- [FM.SQL.InsertOrUpdateRecords](FMSQLInsertOrUpdateRecords.md)
- [FM.SQL.InsertRecordsToSQL](FMSQLInsertRecordsToSQL.md)
- [JSON.InsertRecord](JSONInsertRecord.md)
- [JSON.InsertRecords](JSONInsertRecords.md)
- [SQL.Execute](SQLExecute.md)
- [SQL.NewCommand](SQLNewCommand.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.
    - Rewrote [SQL.InsertRecords](https://www.mbsplugins.eu/SQLInsertRecords.shtml) to use newer code base.
- **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.3**
    - Added IgnoreDuplicates parameter to [SQL.InsertRecords](http://www.mbsplugins.eu/SQLInsertRecords.shtml) functions to ignore duplicate error on insert.
- **Version 7.2**
    - Changed [FM.SQL.InsertRecordsToSQL](http://www.mbsplugins.eu/FMSQLInsertRecordsToSQL.shtml) to no longer quote by default.
    - Fixed [SQL.InsertRecords](http://www.mbsplugins.eu/SQLInsertRecords.shtml) to handle floating point numbers better.

### Example Databases

- [SQL to other databases/ODBC Query](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/SQL%20to%20other%20databases/ODBC%20Query.shtml#4ScriptAnchor_)
- [SQL to other databases/SQLite fun](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/SQL%20to%20other%20databases/SQLite%20fun.shtml#12ScriptAnchor_)
- [Third Party/FileMaker Snippet Storage](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Third%20Party/FileMaker%20Snippet%20Storage.shtml#46CustomFunctionAnchor_)

### Blog Entries

- [MBS FileMaker Plugin, version 16.1pr1](https://www.mbsplugins.de/archive/2026-02-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [Moving data from ODBC to FileMaker via script](https://www.mbsplugins.de/archive/2023-02-12/Moving_data_from_ODBC_to_FileM/monkeybreadsoftware_blog_filemaker)
- [Can FileMaker connect to a Microsoft Access database?](https://www.mbsplugins.de/archive/2019-12-29/Can_FileMaker_connect_to_a_Mic/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 7.3pr1](https://www.mbsplugins.de/archive/2017-06-05/MBS_FileMaker_Plugin_version_7/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 7.2pr3](https://www.mbsplugins.de/archive/2017-04-19/MBS_FileMaker_Plugin_version_7/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 5.2pr9](https://www.mbsplugins.de/archive/2015-08-01/MBS_FileMaker_Plugin_version_5/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 2/2022, Seite 29](https://filemaker-magazin.de/neuigkeit/4174-Appetithappen-FMM_202202)

This function checks for a license.

Created 29th July 2015 , last changed 15th October 2021

  
[SQL.InsertOrUpdateRecords](SQLInsertOrUpdateRecords.md) - [SQL.InternalSQLiteLibrary.Activate](SQLInternalSQLiteLibraryActivate.md)

[HTML Version](SQLInsertRecords.shtml)