---
title: "How to Programmatically Check Whether a Database Table Contains a Specified Column in Magento 2?"
url: "https://magecomp.com/blog/programmatically-check-database-table-contains-specified-column-magento-2/"
date: "2021-08-27T17:46:37+00:00"
modified: "2025-02-19T05:06:11+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 214
reading_time: "2 min read"
summary: "Hello Magento Friends,"
description: "Check whether a specified column exists in your Magento 2 database or not. $isExist =  $setup->getConnection()->tableColumnExists"
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "Magento 2: How to Add Download Invoice Button in Order Email?"
    url: "https://magecomp.com/blog/magento-2-add-download-invoice-button-in-order-email/"
  - title: "How to display percentage discount in Magento 2 product details page"
    url: "https://magecomp.com/blog/display-percentage-discount-magento-2-product-details-page/"
  - title: "How to Upgrade Magento"
    url: "https://magecomp.com/blog/how-to-upgrade-magento/"
---

# How to Programmatically Check Whether a Database Table Contains a Specified Column in Magento 2?

_Published: August 27, 2021_  
_Author: Dhiren Vasoya_  

![How to Programmatically Check Whether a Database Table Contains a Specified Column in Magento 2](https://magecomp.com/blog/wp-content/uploads/2021/08/How-to-Programmatically-Check-Whether-a-Database-Table-Contains-a-Specified-Column-in-Magento-2-1024x512.webp)

**Hello Magento Friends,**

Today’s topic is How to Programmatically Check Whether a Database Table Contains a Specified Column in Magento 2? Do have a look at our recently published blog, [**How to Get User Information Inside of Controller in Magento 2**](https://magecomp.com/blog/get-user-information-inside-of-controller-magento-2/).
[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-2.webp)](https://magecomp.com/magento-performance-optimization.html)

While dealing with a database, the developer needs to check whether a particular column is available in a database table or not. This is usually required while applying some logic to the database. Follow the steps to Programmatically Check Whether a Database Table Contains a Specified Column in Magento 2.
## Steps to Programmatically Check Whether a Database Table Contains a Specified Column in Magento 2:
**Step 1:** Navigate to the below path
**app\code\Vendor\Extension\Setup\Recurring.php**

And add the below code
```
namespace VendorExtensionSetup

use MagentoFrameworkDBDdlTable;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;

Class Recurring implements MagentoFrameworkSetupInstallSchemaInterface
{
    public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
	           $isExist =  $setup->getConnection()->tableColumnExists(
            $setup->getTable(‘Table_Name’),
            ‘Column_Name’
        );
    }
}
```

## [![hyva theme development](https://magecomp.com/blog/wp-content/uploads/2025/02/hyva-theme-development-CTA-1.webp)](https://magecomp.com/services/hyva-theme-development/)

## Conclusion:
Hence, this way you can Programmatically Check Whether a Database Table Contains a Specified Column in Magento 2. If you have any doubts, ask me in the comment box without hesitation. Do share the solution with your friends and stay updated with us.
[![Hire Magento Programmer](https://magecomp.com/blog/wp-content/uploads/2025/02/Hire-Magento-Programmer-CTA-2.webp)](https://magecomp.com/services/hire-magento-programmer/)

**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/programmatically-check-database-table-contains-specified-column-magento-2/](https://magecomp.com/blog/programmatically-check-database-table-contains-specified-column-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-17 18:50:03 UTC_  
