At 4:00 7/27/04, Paul DuBois wrote:
>
>At 16:22 -0500 7/26/04, Ghate, Shishir wrote:
>>I looked at the SHOW COLUMNS statement and they have what I want,
>>but I need to condition off them. For example, I don't want to
>>execute an ALTER TABLE command to add a column if that column is
>>already there. I've tried IF DOES NOT EXIST SHOW COLUMN ...
>>followed by the ALTER TABLE command, but the if check doesn't seem
>>to work on SHOW COLUMNS.
>>
>>Am I missing something, or is this just something that is not supported?
>
>You can process the output of SHOW COLUMNS in your application language
>and use the result to construct the ALTER TABLE statement.
>
>I assume that you're using some kind of programming API to access MySQL
>here. If you're asking "is this supported using SQL alone?" the
>answer is no.
Any chance 'IF EXISTS' being added to the 'ALTER TABLE' statements?
It sure would be nice to execute something like:
ALTER TABLE tmp ADD INDEX joy ( to, the, world ) IF EXISTS;
This seems much more elegant than (pseudo code):
$NewIndexName = "joy";
$Results = run_query( "show index from tmp" );
$FoundIndex = 0;
while ( $Results.hasNext() )
{
$IndexName = $Results.getString( 3 );
if ( $IndexName == $NewIndexName )
{
$FoundIndex = 1;
}
}
if ( ! $FoundIndex )
{
run_update( "alter table tmp add index joy( to, the, world );
}
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]