Solved

Use FeatureWriter to delete SQL table records

  • 22 February 2021
  • 3 replies
  • 47 views

Badge +1

Hi

Want to delete all rows from my SQL table. Created the following FeatureWriter to set to delete:FeatureWriter DeleteHowever, ran it in my workbench and the database records are still not deleted. Anything that I did wrong? Thanks.

icon

Best answer by nielsgerrits 23 February 2021, 19:01

View original

3 replies

Userlevel 6
Badge +32

What is the input? A single feature to initiate the proces? Then you can change the Row Selection to Where Clause and enter 1=1. As this is always true it will delete all records.

 

Edit: I see you have put the Table Handling to Truncate Existing. From the documentation:

Truncate Existing: If destination table/list does not exist, the translation will fail. Otherwise, delete all rows from existing table or list.

So this feels not correct. What do you want to achieve? Do you want to write records to a table, and clean the table before writing? Then you just can use Insert and Truncate Existing.

Badge +1

Hi nielsgerrits,

Actually what I wanted to achieve is to delete all records in a SQL database table (far left) and then import from another source into the same table again:

FME 2Basically we just want to refresh the SQL table with new records. Hope this helps.

Userlevel 6
Badge +32

Hi nielsgerrits,

Actually what I wanted to achieve is to delete all records in a SQL database table (far left) and then import from another source into the same table again:

FME 2Basically we just want to refresh the SQL table with new records. Hope this helps.

I think this technically should work, you only need one feature to initiate the FeatureWriter. You can do this by connecting a Creator transformer before the FeatureWriter. It does not matter what it does output, as it's only to start the FeatureWriter.

 

A more usual way to do this is to use the database function "Truncate" in the writer on the right side. It then removes all records from the table prior to inserting the new ones.

Reply