How to check column exists or not in table using MySQL

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.

Answers 1
  • 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';
    
    0

    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