checking presence of table columns in mysql

George Toft plug-discuss@lists.plug.phoenix.az.us
Tue, 11 Feb 2003 07:35:05 -0500


Lynn David Newton wrote:
> =

> Since there seems to be some mysql expertise on the
> list: Does anyone know of a SQL based way to check for
> the existence of a particular column by name? This came
> up in work today. I've never been able to do it. I'm
> not so sure it's possible.
> =

> --
> Lynn David Newton
> Phoenix, AZ
> ---------------------------------------------------
> PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
> To subscribe, unsubscribe, or to change  you mail settings:
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss


Not purely sql, but close:
mysql -uwhomever -ppassword -hhost database -e "describe table" | grep
fieldnamee

For example:
$ mysql -uuser -ppassword -haaron database -e "describe day" | grep -c
create_ts
1

(the names of the user/password/database have been changed :) )


George
-- =

Discover . . .         | Free Computer Security Information
        <=B7=B7=B7> Secure   | http://www.georgetoft.com/security
         Networking    | =

@http://georgetoft.com | Lock your box - keep your affairs private!