For each


I have a simple beginners doubt :D

Is it better to use a simple query with a FOR EACH to delete all the records from one ENTITY or
to use an Avanced query to delete all the records at once?

This conflicts between the best practices documentation where its better to use simple queries over advanced ones, but in this case it feels better.
If we have a huge number of records the cycle might take to long to execute.
Or does outsystems optimizes the code and performs Delete to the entire table?

Cumprimentos Carlos Vinhas
Hi Carlos, 

OutSystems does not optimizes the code on this case... One of the big concerns with "advanced queries" are related with his usage to retrieve complex lists and or large entities (entities with large number of columns).  

For your purpose, keep using Advanced Queries. 

Rafael Pereira
We don't have any optimization in place to turn that particular pattern into a simple DELETE statement.

If you're running into actual performance problems because of deleting rows one by one, then I'd suggest using an advanced query to make a delete statement.

Always remember to take best-practices recommendations with a grain of salt. In this case we're advising that database queries are best maintained using simple queries than advanced queries, however the use-case you're describing* isn't really a query, is it? What you want to do is send a command to the database, in this case an Advanced Query is best. Note also that in this particular case the advanced query should require no further maintenance, just make sure it has a good, descriptive name.

*if I understood correctly: deleting all data from a certain entity.

thanks for all the clarification.

My doubt was really about deleting all data from one entity, and has I thought an andvanced query was the fastest way.

Ty for the fast reply, take care.