Timothy Chi writes:
> Does anyone know how to check for the existance of a specific table, column,
> and/or keys within MySQL?
>
> For instance, I need to run an ALTER TABLE command to change a column name,
> but only want to do this if it hasn't been done already.
>
> In MS SQL Server 7, I would do something like:
>
> if exists (select * from sysobjects where id =
> object_id(N'[dbo].[system_registry]') and OBJECTPROPERTY(id, N'IsUserTable')
> = 1)
> alter table system_registry ....
> go
>
> I not only need to check columns names, but if various primary keys have
> been established (and if not, create them).
>
> Thanks in advance,
>
> --Tim
> tchi@stripped
>
>
>
HI!
You can also do this, but from some client program, including Unix
shell script.
Tables and column existance can be checked by SELECT, and then errno
of query result can be analyzed. For key you should analyze the output
from show index command.
In both cases it is rather simple, but it has to be made as a simple,
very simple program, which as I said can be a simple shell script !
Sinisa
+----------------------------------------------------------------------+
| TcX ____ __ _____ _____ ___ == mysql@stripped |
| /*/\*\/\*\ /*/ \*\ /*/ \*\ |*| Sinisa Milivojevic |
| /*/ /*/ /*/ \*\_ |*| |*||*| mailto:sinisa@stripped|
| /*/ /*/ /*/\*\/*/ \*\|*| |*||*| Larnaka, Cyprus |
| /*/ /*/ /*/\*\_/*/ \*\_/*/ |*|____ |
| ^^^^^^^^^^^^/*/^^^^^^^^^^^\*\^^^^^^^^^^^ |
| /*/ \*\ Developers Team |
+----------------------------------------------------------------------+