How to check if column exists in MySQL table

SELECT * 
FROM information_schema.COLUMNS 
WHERE 
    TABLE_SCHEMA = 'db_name' 
AND TABLE_NAME = 'table_name' 
AND COLUMN_NAME = 'column_name'
Advertisements

Track db table schema changes using phpmyadmin

This is only for PHPMyAdmin users.

If you are using the mysql database , phpmyadmin offers lot of features to ease our database management tasks.
One of the task we usually come across is to keep log of schema changes in database table, like new fields addition, existing fields change, etc.
The traditional way how we do that is, we keep a list of sqls in a text file and pass this text file if anybody needs the schema change sqls. Well this is nice way, but
it requires us to make sure this file
1. Contains all the schema change sqls
2. Located to known place and can be easily retrieved. Remember where this file is, and is it correct? (this is for people with bad memory, like me)

Well I think the smarter way would be to use “tracking” feature of “Phpmyadmin”.
1. Click on “tracking” link from main menu of phpmyadmin.
2. It will show us list of untracked tables, click on “track table” link to start tracking the schema changes.

The drawback of this “tracking” is , you will need to start tracking from beginning i.e. when you created the table. This also means that the time you start tracking your tables schema changes will get recorded schema from that time. So, early bird wins here.

Since release 3.3.x a tracking mechanism is available.

For more details https://wiki.phpmyadmin.net/pma/Change_tracking.