Records can be deleted in two ways: by filter, or by all existing records.
To delete only one or more records of a database table, you must configure the SQL code of the Query so that there is a filter which selects what data to erase. This is the SQL code structure.
DELETE FROM (function used) TABLENAME (table used) WHERE FIELDNAME (field of the variable used as a filter) = FIELDVALUE
As shown in the next example.
Figure 1: SQL code example using the DELETE FROM clause
NOTE: For the Access database, add * between DELETE and FROM. In case of SQL Server or Oracle databases, this is not necessary.
To delete all records from a database, you must configure the SQL code of the Query this way:
DELETE (function used) FROM TABLENAME (table to erase)
As shown in the next example.
Figure 2: SQL code example using the DELETE clause
Exercise
- Create a Query and a button which delete only a record of the filter.
- Create a Query and a button which delete all records of a Historic.