checking presence of table columns in mysql
Brian Tafoya
plug-discuss@lists.plug.phoenix.az.us
Tue, 11 Feb 2003 07:15:50 -0700
Oopps! I pasted the wrong statement... here is the correct ones:
SHOW FIELDS FROM `tbl_accts_xref_groups`;
SHOW KEYS FROM `tbl_accts_xref_groups`;
Brian
----- Original Message -----
From: "Lynn David Newton" <lynn.newton@cox.net>
To: <plug-discuss@lists.plug.phoenix.az.us>
Sent: Tuesday, February 11, 2003 6:51 AM
Subject: Re: checking presence of table columns in mysql
>
> >> 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.
>
> George> Not purely sql, but close:
> George> mysql -uwhomever -ppassword -hhost database -e "describe table"
| grep
> George> fieldnamee
>
> George> For example:
> George> $ mysql -uuser -ppassword -haaron database -e "describe day" |
grep -c
> George> create_ts
> George> 1
>
> Right, I've done that. That's something that's simple
> in the shell. I was looking for something that works
> through Perl. Yeah, I could run system("blah blah") and
> munge the data, but that's so primitive.
>
> As it turns out, the statement handle attributes in DBI
> inherit all the metadata one is likely to be interested
> in: number of fields, field names, field types, etc.
> That's the sophisticated way to go.
>
> Thanks for your suggestion.
>
> --
> 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
>