When to analyze database?

Hi,
I understand that from time to time, a database should be analyzed in order to keep it running efficiently.

The question I have is where should I put this code?
Is it better to put it in the window open event of the window containing the database / listbox, or should it be inserted after adding to or deleting from the database?

SQLexecute("analyze")

Thank you.

I would recommend in the step right after your backup code.

It’s a high cost maintenance operation. Not intended to be used after inserts/deletes. Just periodically. A good time to use it is when you “stop” to do some maintenance operations. After a successful backup seems a very appropriated time, if some crash happens you are covered. Backups are a daily job, analyzes could be a weekly job.

If my database is called myFantasticDatabase.db - is my code syntax below correct?

myFantasticDatabase.db.SQLExecute("Analyze")

And is there anything else I need to do, as that 1 line seems a bit too simple?

Thank you all in advance.

Analyze is decidedly simple