Coolness

While talking with Dynom and Davey I learned something really cool today - how to get the declared definition of a column all by itself with MySQL (I used version 5.0.45). Yes there are lots of other ways to get the info - not the least of which is using the information_schema - but this just struck me as being way cool.

You can even use wildcards in the column name. From a different database (note you have to have the perms to access the alternate database):


DESCRIBE Db.table column;

Example from my test db:

mysql> describe lig_test.student guardianship;
+--------------+---------+------+-----+---------+-------+
| Field        | Type    | Null | Key | Default | Extra |
+--------------+---------+------+-----+---------+-------+
| guardianship | char(1) | NO   |     |         |       |
+--------------+---------+------+-----+---------+-------+
1 row in set (0.08 sec)

mysql> describe lig_test.student 'guard%';
+----------------+----------+------+-----+---------+-------+
| Field          | Type     | Null | Key | Default | Extra |
+----------------+----------+------+-----+---------+-------+
| guardian_photo | longblob | YES  |     | NULL    |       |
| guardianship   | char(1)  | NO   |     |         |       |
+----------------+----------+------+-----+---------+-------+
2 rows in set (0.01 sec)
del.icio.us:Coolness  digg:Coolness  furl:Coolness  reddit:Coolness

3 Responses to Coolness

  1. Raj Shekhar :

    Nice one. Works on 4.1 too. Thanks.

    PS: welcome back to the internet ;-)

  2. cereal_girl :

    Beautiful. I will put it to good use before the day is done.
    Lig, you rock!

  3. PHP Encoder :

    Hoho! So nice, thanks for this tip!

Leave a Reply