FM.ExecuteFileSQLOnIdle
-----------------------

Executes a SQL command at idle time.

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

MBS( "FM.ExecuteFileSQLOnIdle"; SQL Statement; FileName { ; Column Delimiter; Record Delimiter; Params... } ) 

**MBS**( **"FM.ExecuteFileSQLOnIdle";** /\* Executes a SQL command at idle time. \*/  
**$SQL Statement**; /\* the SQL statement \*/   
**$FileName**; /\* The file name of the database.  
  
Using a table in another database file may require you adding the other file as an external data source and adding the external table to your relationship graph to grant access.e.g. Get(FileName) \*/   
**$Column Delimiter**; /\* Optional; Columns Separator.   
Default is tab character, which has unicode code point 9.  
You can pass delimiter as text (one character only) or as unicode code point (as number).e.g. 9 \*/   
**$Record Delimiter**; /\* Optional; Record Separator.  
Default is return character, which has unicode code point 13.  
You can pass delimiter as text (one character only) or as unicode code point (as number).e.g. 13 \*/   
**$Params...**) /\* Optional; Optional, pass here parameters. One parameter to this function for each parameter you want to pass to the SQL statement.e.g. 123 \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| SQL Statement | the SQL statement |  |  |
| FileName | The file name of the database.      Using a table in another database file may require you adding the other file as an external data source and adding the external table to your relationship graph to grant access. | Get(FileName) |  |
| Column Delimiter | Columns Separator.    Default is tab character, which has unicode code point 9.   You can pass delimiter as text (one character only) or as unicode code point (as number). | 9 | Optional |
| Record Delimiter | Record Separator.   Default is return character, which has unicode code point 13.   You can pass delimiter as text (one character only) or as unicode code point (as number). | 13 | Optional |
| Params... | Optional, pass here parameters. One parameter to this function for each parameter you want to pass to the SQL statement. | 123 | Optional |

### Result

Returns OK or error.

### Description

Executes a SQL command at idle time.  
This is similar to [FM.ExecuteFileSQL](FMExecuteFileSQL.md), except that it waits until idle to execute..   
You run a script pause after using this function to give it time to execute.  
See the other function for more info.  
  
Seems like on FileMaker 11 you get LastError 8310 if you use fields with underscore in the name. You avoid that by placing the field names in quotes.  
Use [FM.ExecuteSQL.LastErrorMessage](FMExecuteSQLLastErrorMessage.md) and [FM.ExecuteSQL.LastError](FMExecuteSQLLastError.md) to see error message.  
  
You can do more schema changes via ODATA interface on FileMaker Server including changing or renaming fields.  
  
Please notice that FM.ExecuteFileSQLOnIdle and [FM.ExecuteFileSQL](FMExecuteFileSQL.md) have the filename parameter on different positions.  
  
This function takes variable number of parameters. Pass as much parameters as needed separated by the semicolon in FileMaker.  
Please repeat Params parameter as often as you need.  
### Examples

Create a new text field in a table:

 MBS ("[FM.ExecuteSQLOnIdle](FMExecuteSQLOnIdle.md)";"ALTER TABLE TestTable ADD MyField varchar")  
Create in a script and check error:

 # set command to run   
Set Variable \[ $r ; Value: MBS ("FM.ExecuteFileSQLOnIdle"; "ALTER TABLE Kontakte ADD MyField varchar"; "Kontakte.fmp12") \]   
\# Make pause to run it   
Pause/Resume Script \[ Duration (seconds): ,1 \]   
\# Check error status   
Set Variable \[ $errorNumber ; Value: MBS ( "[FM.ExecuteSQL.LastError](FMExecuteSQLLastError.md)" ) \]   
Set Variable \[ $errorMessage ; Value: MBS ( "[FM.ExecuteSQL.LastErrorMessage](FMExecuteSQLLastErrorMessage.md)" ) \]  
Create a field:

 Set Variable \[ $r ; Value: MBS ("FM.ExecuteFileSQLOnIdle";"ALTER TABLE TestTable ADD MyField varchar"; Get(FileName)) \]   
Pause/Resume Script \[ Duration (seconds): ,1 \]   
If \[ MBS ("[FM.ExecuteSQL.LastError](FMExecuteSQLLastError.md)") ≠ 0 \]   
 Show Custom Dialog \[ "Failed to add field" ; MBS ("[FM.ExecuteSQL.LastError](FMExecuteSQLLastError.md)") &amp; ": " &amp; MBS ("[FM.ExecuteSQL.LastErrorMessage](FMExecuteSQLLastErrorMessage.md)") \]   
Else  
 Show Custom Dialog \[ "Added field." ; "OK" \]   
End If  
Create a new text field in a table with variables for the names:

 Set Variable \[ $TableName ; Value: "TestTable" \]   
Set Variable \[ $FieldName ; Value: "MyField" \]   
Set Variable \[ $FieldType ; Value: "VARCHAR" \]   
  
Set Variable \[ $r ; Value: MBS ("FM.ExecuteFileSQLOnIdle";"ALTER TABLE \\"" &amp; $TableName &amp; "\\" ADD \\"" &amp; $FieldName &amp; "\\" " &amp; $FieldType &amp; " " ; Get(FileName)) \]   
Pause/Resume Script \[ Duration (seconds): ,1 \]   
If \[ MBS ("[FM.ExecuteSQL.LastError](FMExecuteSQLLastError.md)") ≠ 0 \]   
 Show Custom Dialog \[ "Error adding field" ; MBS ("[FM.ExecuteSQL.LastError](FMExecuteSQLLastError.md)") &amp; ": " &amp; MBS ("[FM.ExecuteSQL.LastErrorMessage](FMExecuteSQLLastErrorMessage.md)") \]   
Else  
 Show Custom Dialog \[ "Added field" ; "OK" \]   
End If  
Create a table:

 Set Variable \[ $r ; Value: MBS ("FM.ExecuteFileSQLOnIdle";"CREATE TABLE \\"TestTable\\" (ID INT PRIMARY KEY, MyTextField VARCHAR, MyNumberField DECIMAL)"; Get(FileName)) \]   
\# for details see fm16\_sql\_reference.pdf (or newer) from Claris Inc.   
Rename field:

 MBS ("FM.ExecuteFileSQLOnIdle"; "ALTER TABLE Kontakte RENAME COLUMN Feld TO Feld2"; Get(FileName))  
// Needs FileMaker 22.0 or newer  
Create two tables with relationship:

 Set Variable \[ $r ; Value: MBS ("FM.ExecuteFileSQLonIdle"; "CREATE TABLE Departments ( DepartmentID int PRIMARY KEY, Name varchar(100) NOT NULL )"; ""; "") \]  
Pause/Resume Script \[ Duration (seconds): ,1 \]  
If \[ MBS ("[FM.ExecuteSQL.LastError](FMExecuteSQLLastError.md)") \]  
 Show Custom Dialog \[ "SQL failed" ; MBS ("[FM.ExecuteSQL.LastErrorMessage](FMExecuteSQLLastErrorMessage.md)") \]  
End If  
\#   
Set Variable \[ $r ; Value: MBS ("FM.ExecuteFileSQLonIdle"; "CREATE TABLE Employees ( EmployeeID int PRIMARY KEY, Name varchar(100) NOT NULL, DepartmentID int FOREIGN KEY REFERENCES Departments(DepartmentID) )"; ""; "") \]  
Pause/Resume Script \[ Duration (seconds): ,1 \]  
If \[ MBS ("[FM.ExecuteSQL.LastError](FMExecuteSQLLastError.md)") \]  
 Show Custom Dialog \[ "SQL failed" ; MBS ("[FM.ExecuteSQL.LastErrorMessage](FMExecuteSQLLastErrorMessage.md)") \]  
End If  
\# Requires FileMaker 2026 or newer.   
Add a new field with relationship:

 Set Variable \[ $r ; Value: MBS ("FM.ExecuteFileSQLonIdle"; "ALTER TABLE Assets ADD DepartmentID int FOREIGN KEY REFERENCES Departments(DepartmentID)"; ""; "") \]  
Pause/Resume Script \[ Duration (seconds): ,1 \]  
If \[ MBS ("[FM.ExecuteSQL.LastError](FMExecuteSQLLastError.md)") \]  
 Show Custom Dialog \[ "SQL failed" ; MBS ("[FM.ExecuteSQL.LastErrorMessage](FMExecuteSQLLastErrorMessage.md)") \]  
End If  
\# Requires FileMaker 2026 or newer.   
### See also

- [FM.ExecuteFileSQL](FMExecuteFileSQL.md)
- [FM.ExecuteFileSQLValue](FMExecuteFileSQLValue.md)
- [FM.ExecuteSQL](FMExecuteSQL.md)
- [FM.ExecuteSQL.LastError](FMExecuteSQLLastError.md)
- [FM.ExecuteSQL.LastErrorMessage](FMExecuteSQLLastErrorMessage.md)
- [FM.ExecuteSQLOnIdle](FMExecuteSQLOnIdle.md)

### Release notes

- **Version 12.2**
    - Marked [FM.ExecuteSQLOnIdle](https://www.mbsplugins.eu/FMExecuteSQLOnIdle.shtml) as deprecated in favor of newer [FM.ExecuteFileSQLOnIdle](https://www.mbsplugins.eu/FMExecuteFileSQLOnIdle.shtml) function.

### Blog Entries

- [FileMaker 2026 released](https://www.mbsplugins.de/archive/2026-06-10/FileMaker_2026_released/monkeybreadsoftware_blog_filemaker)
- [Storing data in the FileMaker schema](https://www.mbsplugins.de/archive/2024-05-09/Storing_data_in_the_FileMaker_/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 12.2pr1](https://www.mbsplugins.de/archive/2022-04-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 6.5pr3](https://www.mbsplugins.de/archive/2016-10-18/MBS_FileMaker_Plugin_version_6/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

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

This function checks for a license.

Created 16th October 2016 , last changed 21st May 2026

  
[FM.ExecuteFileSQL](FMExecuteFileSQL.md) - [FM.ExecuteFileSQLValue](FMExecuteFileSQLValue.md)

[HTML Version](FMExecuteFileSQLOnIdle.shtml)