Drop or remove Table from Database using DataPatchInterface Magento 2.

Drop or Remove a database Table in Magento 2 using the Setup folder DataPatchInterface approach.

From Magento 2.3 New Concept Setup Patch  Data was introduced.

You need to create a PHP file under your module Setup/Patch/Data folder.

Lets we create the Jesadiya_DropTable module with RemoveExtraTable.php file.  Our table name is image_storage_tmp is resided in the Magento 2 database.

File path: app/code/Jesadiya/DropTable/Setup/Patch/Data/RemoveExtraTable.php

In the above code we have used SchemaSetupInterface to call dropTable() function.

In the script, We first checking if the table exists in the database or not, If the table exists, remove it from the database otherwise skip it.

Run bin/magento setup:upgrade command to remove a table from the database.