FM.DeleteRecords
----------------

Deletes existing records in a table in one line.

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

MBS( "FM.DeleteRecords"; FileName; TableName; IDField; IDValue { ; IDField2; IDValue2; IDField3; IDValue3 } ) 

**MBS**( **"FM.DeleteRecords";** /\* Deletes existing records in a table in one line. \*/  
**$FileName**; /\* The file name of where the table is inside. Can be empty to look for the table in all files.e.g. Get(FileName) \*/   
**$TableName**; /\* The name of the table to delete records from.  
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" \*/   
**$IDField**; /\* The name of the field which provides an unique ID for each record, so we can identify the field.  
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. "ID" \*/   
**$IDValue**; /\* The value for the ID field to identify the record.  
Data type of parameter must match the data type of the field.e.g. $RecordID \*/   
**$IDField2**; /\* Optional; The name of the second field which provides an unique ID for each record, so we can identify the field.  
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. "PersonID" \*/   
**$IDValue2**; /\* Optional; The value for second ID field to identify the record.  
Data type of parameter must match the data type of the field.e.g. $PersonID \*/   
**$IDField3**; /\* Optional; The name of the third field which provides an unique ID for each record, so we can identify the field.  
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. "CompanyID" \*/   
**$IDValue3**) /\* Optional; The value for third ID field to identify the record.  
Data type of parameter must match the data type of the field.e.g. $CompanyID \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| FileName | The file name of where the table is inside. Can be empty to look for the table in all files. | Get(FileName) |  |
| TableName | The name of the table to delete records from.   Can be ID of table, so we lookup name by ID.    Can be result of GetFieldName() function as we remove field name automatically. | "Assets" |  |
| IDField | The name of the field which provides an unique ID for each record, so we can identify the field.   Can be ID of field, so we lookup name by ID.    Can be result of GetFieldName() function as we remove table name automatically. | "ID" |  |
| IDValue | The value for the ID field to identify the record.   Data type of parameter must match the data type of the field. | $RecordID |  |
| IDField2 | The name of the second field which provides an unique ID for each record, so we can identify the field.   Can be ID of field, so we lookup name by ID.    Can be result of GetFieldName() function as we remove table name automatically. | "PersonID" | Optional      Added in version **8.2**. |
| IDValue2 | The value for second ID field to identify the record.   Data type of parameter must match the data type of the field. | $PersonID | Optional      Added in version **8.2**. |
| IDField3 | The name of the third field which provides an unique ID for each record, so we can identify the field.   Can be ID of field, so we lookup name by ID.    Can be result of GetFieldName() function as we remove table name automatically. | "CompanyID" | Optional      Added in version **8.2**. |
| IDValue3 | The value for third ID field to identify the record.   Data type of parameter must match the data type of the field. | $CompanyID | Optional      Added in version **8.2**. |

### Result

Returns OK or error.

### Description

Deletes existing records in a table in one line.  
You pass to this function table name (and optional filename).  
To identify the record you pass the name of the ID field and the value for the record. The ID field must not be unique, so several records can be updated at once.  
  
Please note that [FM.DeleteRecord](FMDeleteRecord.md) and FM.DeleteRecords are nearly identical. Just [FM.DeleteRecord](FMDeleteRecord.md) provides the check to make sure only one record matches while FM.DeleteRecords allows several records to be deleted. So with FM.DeleteRecords you can easily erase a lot of data if you pass wrong ID!  
  
With plugin version 7.2 or later, you can specify fields and table via IDs and the plugin will lookup them for you at runtime. Table IDs and table names must be unique across all open files for this to work correctly.  
  
Version 8.2 allows to specify up to 3 ID parameters.  
  
With plugin version 8.4 or newer, you can use GetFieldName() function to query field names and the plugin removes the table prefix with :: in the field name before passing it to SQL engine.  
  
You can use [FM.ExecuteSQL.LastSQL](FMExecuteSQLLastSQL.md) function to see later what SQL was created and run.  
### Examples

Delete records based on values:

 Set Variable \[ $r ; Value: MBS ( "FM.DeleteRecords"; Get(FileName); "Contacts"; "First"; "Christian"; "Last"; "Schmitz"; "Company"; "Test Inc.") \]  
Delete records with empty field:

 MBS ( "[FM.ExecuteFileSQL](FMExecuteFileSQL.md)"; Get(FileName); "DELETE FROM \\"Contacts\\" WHERE \\"Company\\" IS NULL ")  
  
// we need to do SQL with checking for NULL as comparison with "" doesn't work.  
### See also

- [FM.DeleteRecord](FMDeleteRecord.md)
- [FM.ExecuteFileSQL](FMExecuteFileSQL.md)
- [FM.ExecuteSQL](FMExecuteSQL.md)
- [FM.ExecuteSQL.LastSQL](FMExecuteSQLLastSQL.md)
- [FM.UpdateRecords](FMUpdateRecords.md)
- [JSON.DeleteRecords](JSONDeleteRecords.md)

### Release notes

- **Version 14.0**
    - Changed [FM.DeleteRecords](https://www.mbsplugins.eu/FMDeleteRecords.shtml) to return OK if no record was found.
- **Version 10.1**
    - Changed [FM.InsertRecord](https://www.mbsplugins.eu/FMInsertRecord.shtml), [FM.CompareTables](https://www.mbsplugins.eu/FMCompareTables.shtml), [FM.DeleteRecord](https://www.mbsplugins.eu/FMDeleteRecord.shtml), [FM.DeleteRecords](https://www.mbsplugins.eu/FMDeleteRecords.shtml), [FM.InsertOrUpdateRecord](https://www.mbsplugins.eu/FMInsertOrUpdateRecord.shtml) and [FM.UpdateRecord](https://www.mbsplugins.eu/FMUpdateRecord.shtml) to take table name from first field name if table name is empty.
- **Version 8.2**
    - Upgraded [FM.DeleteRecord](http://www.mbsplugins.eu/FMDeleteRecord.shtml) and [FM.DeleteRecords](http://www.mbsplugins.eu/FMDeleteRecords.shtml) to accept 1 to 3 ID values.

### Example Databases

- [CURL/Email/IMAP Email List](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/Email/IMAP%20Email%20List.shtml#1ScriptAnchor_)
- [CURL/Email/IMAP Email](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/Email/IMAP%20Email.shtml#1ScriptAnchor_)

### Blog Entries

- [MBS FileMaker Advent calendar - Door 16 - Delete](https://www.mbsplugins.de/archive/2025-12-16/MBS_FileMaker_Advent_calendar_/monkeybreadsoftware_blog_filemaker)
- [Insert or update with JSON](https://www.mbsplugins.de/archive/2024-08-28/Insert_or_update_with_JSON/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 14.4pr4](https://www.mbsplugins.de/archive/2024-08-26/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 14.0pr8](https://www.mbsplugins.de/archive/2024-01-12/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 10.1pr1](https://www.mbsplugins.de/archive/2020-01-30/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 8.2pr1](https://www.mbsplugins.de/archive/2018-04-04/MBS_FileMaker_Plugin_version_8/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 5.5pr3](https://www.mbsplugins.de/archive/2015-12-19/MBS_FileMaker_Plugin_version_5/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 6/2018, Seite 24](https://filemaker-magazin.de/neuigkeit/4025-Appetithappen-FMM_201806)
- [Ausgabe 3/2018, Seite 36](https://filemaker-magazin.de/neuigkeit/3953-Appetithappen-FMM_201803)

This function is free to use.

Created 11st December 2015 , last changed 19th September 2021

  
[FM.DeleteRecord](FMDeleteRecord.md) - [FM.DisableMouseWheel](FMDisableMouseWheel.md)

[HTML Version](FMDeleteRecords.shtml)