List:General Discussion« Previous MessageNext Message »
From:sheeri kritzer Date:May 25 2006 1:24am
Subject:Re: How do I add a column only if it doesn't exist?
View as plain text  
I don't think MySQL can do that....maybe with some kind of stored procedure....

If you're using 5.0 or higher, use the INFORMATION SCHEMA to find out
if the column exists.  If not, use the "show create table" statement
and parse it.

Why is this a problem, though?  (just curious, I'm not sure this would
ever come up.  I don't do automatic schema changes, always do them
manually, so I'm not too sure why you'd be amiss....unless you're
running gobs of servers and some of them have the column and some of
them don't.....but even then you could run a script that alters the
table to add the column and just let it thrown an error if it already


On 5/24/06, Daevid Vincent <daevid@stripped> wrote:
> I want to do something like this:
> if not exists `hotel_page_templates`.`hpt_custom_fields`
> alter table `hotel_page_templates` add column `hpt_custom_fields` text after
> `hpt_alternate_username`;
> --
> MySQL General Mailing List
> For list archives:
> To unsubscribe:
How do I add a column only if it doesn't exist?Daevid Vincent24 May
Re: How do I add a column only if it doesn't exist?sheeri kritzer25 May