KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: TRUNCATE TABLE can bypass triggers
PRODUCT: 4D Developer | VERSION: 11.2 | PLATFORM: Mac & Win
Published On: November 20, 2008
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

For a table, Table_1, which is set up to trigger code on deleting a record, how can you quickly delete all records from the table while bypassing the trigger? By using the TRUNCATE TABLE command, new as of 4D v11 SQL Release 2:

TRUNCATE TABLE([Table_1])


It is similar to issuing the following commands:

ALL RECORDS([Table_1])
DELETE SELECTION([Table_1])


But TRUNCATE TABLE will not cause the on delete trigger to run. Also note that referential integrity of the data is not checked, so it should be used carefully.

Commented by Josh Fletcher on May 5, 2009 at 11:39 AM
It would be more correct to say "TRUNCATE TABLE does bypass triggers". It's not optional, triggers do not execute when using TRUNCATE TABLE.