How to check is database table exists or not by Magento 2?

You can verify the given database table available in the database with the help of isTableExists() method by use of Magento\Framework\App\ResourceConnection class.

This method is useful when you are dealing with a database query and want to run your query on the safe side to check whether the first given table exists or not before firing the SQL query.


namespace Rbj\SqlQuery\Model;

use Magento\Framework\App\ResourceConnection;

class CheckTable
    private const CATALOG_PRODUCT_ENTITY_VARCHAR = 'catalog_product_entity_varchar';

    public function __construct(
        private readonly ResourceConnection $resourceConnection
    ) {

    public function execute()
        $connection = $this->resourceConnection->getConnection();
        $catalogVarcharTable = $connection->getTableName(self::CATALOG_PRODUCT_ENTITY_VARCHAR);
        if ($connection->isTableExists($catalogVarcharTable)) {
            // TABLE AVAILABLE

In the above code example, We are checking catalog_product_entity_varchar table exists or not. You can replace it with your table name and just proceed with the SQL query.