List:General Discussion« Previous MessageNext Message »
From:Sasha Pachev Date:June 9 1999 4:51am
Subject:Re: Table exists ?
View as plain text  
Derek Lavine wrote:
> 
> Thanks for the suggestions so far but I think I was not clear enough, sorry.
> 
> What I have is an SQL script that creates a number of tables. Before each
> create I want to check if the table already exists and if it does I will not
> create it. I need to do this as otherwise as soon as an error is encountered
> (which it is if one tries to create a tablethat already exists) the script is
> aborted
> 
> e.g.
> 
> ./mysql -u user -p password mydb < mysqlscript.sql
> 
> if mysqlscript.sql contains a create for a table that is already present the
> script will be aborted. I don't know how (in the script) to check if the
> table is present.
> 
> Is there a way of doing this or will I have to write a perl script that will
> call individual create table scripts if the table does not exist.
> 
> Thanks again
> 
> derek
> 

Here is a dirty trick I use in situations that are probably similar to
yours:

mysql -f -uuser -psecret < file.sql

That will force the script to continue even if an error occurs, quick
and dirty, but does the job.

-- 
Sasha Pachev
http://www.sashanet.com
Thread
Table exists ?Derek Lavine8 Jun
  • Re: Table exists ?Christian Mack8 Jun
  • Re: Table exists ?Jim Faucette8 Jun
  • RE: Table exists ?Jeff Magnusson8 Jun
  • Re: Table exists ?Derek Lavine9 Jun
    • Re: Table exists ?Paul DuBois9 Jun
    • Re: Table exists ?Michael Widenius9 Jun
  • Re: Table exists ?Sasha Pachev9 Jun
  • Re: Table exists ?Ronald Beck9 Jun
RE: Table exists ?tcobb9 Jun