List:General Discussion« Previous MessageNext Message »
From:Michael Widenius Date:June 9 1999 7:00am
Subject:Re: Table exists ?
View as plain text  
>>>>> "Derek" == Derek Lavine <derek@stripped> writes:

Derek> Thanks for the suggestions so far but I think I was not clear enough, sorry.
Derek> What I have is an SQL script that creates a number of tables. Before each
Derek> create I want to check if the table already exists and if it does I will not
Derek> create it. I need to do this as otherwise as soon as an error is encountered
Derek> (which it is if one tries to create a tablethat already exists) the script is
Derek> aborted

Derek> e.g.

Derek> ./mysql -u user -p password mydb < mysqlscript.sql

Derek> if mysqlscript.sql contains a create for a table that is already present the
Derek> script will be aborted. I don't know how (in the script) to check if the
Derek> table is present.

Derek> Is there a way of doing this or will I have to write a perl script that will
Derek> call individual create table scripts if the table does not exist.

Hi!

You can in always use:

./mysql -u user -p password --force mydb < mysqlscript.sql

This will continue your script even in case of errors.

Regards,
Monty

PS: MySQL 3.23 supports the CREATE TABLE IF NOT EXIST syntax.
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