How to check column exists or not in table using MySQL

Created at 28-Jul-2021, By samar

How to check column exists or not in table using MySQL

With this article, we’ll look at some examples of how to address the "How to check column exists or not in table using MySQL" problem.

You can run the SQL query to check the column exists or not in the table. This SQL query returns the column name with data type and other properties.
  • Check column exists or not in a table using SQL

    //SQL Syntax
    SHOW COLUMNS FROM `table` LIKE 'fieldname';
    
    //SQL Query
    SHOW COLUMNS FROM `posts` LIKE 'user_id';
    

    You can check if a column exists or not in MySQL using SQL query SHOW COLUMNS FROM `posts` LIKE 'user_id'; 

    This query will return the column name with the data type after executing the SQL query.

     

     

Back to code snippet queries related sql

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.