Detect if table exists from within MySQL?

2005-10-06 Thread Ryan Stille
I am converting some code from MSSQL to MySQL. In one place I need to have a conditional query depending on if a table exists or not. There are different versions of this application and the table only exists in some of them. Here is how it was done in MSSQL: IF OBJECT_ID('cfgbiz') IS NOT NULL

Re: Detect if table exists from within MySQL?

2005-10-06 Thread Peter Brawley
Ryan, I am converting some code from MSSQL to MySQL. In one place I need to have a conditional query depending on if a table exists or not. There are different versions of this application and the table only exists in some of them. Here is how it was done in MSSQL: If 'SHOW COLUMNS FROM

RE: Detect if table exists from within MySQL?

2005-10-06 Thread Ryan Stille
If 'SHOW COLUMNS FROM tablename' returns error 1146 (42S02), the table doesn't exist. This causes my application (ColdFusion) to throw an exception. If I have to, I could resort to doing another query in my application (SHOW TABLES) and seeing if my table was returned in that list. But I was

Re: Detect if table exists from within MySQL?

2005-10-06 Thread Keith Ivey
Ryan Stille wrote: If I have to, I could resort to doing another query in my application (SHOW TABLES) and seeing if my table was returned in that list. But I was hoping for a more elegant way to do it, within the single query. Maybe you could use SHOW TABLES LIKE 'your_table'; -- Keith

Re: Detect if table exists from within MySQL?

2005-10-06 Thread Jeff Smelser
On Thursday 06 October 2005 10:57 am, Ryan Stille wrote: I am converting some code from MSSQL to MySQL. In one place I need to have a conditional query depending on if a table exists or not. There are different versions of this application and the table only exists in some of them. Here is

RE: Detect if table exists from within MySQL?

2005-10-06 Thread Ryan Stille
Maybe you could use SHOW TABLES LIKE 'your_table'; That's a great idea, I just tried it in several ways, like: IF EXISTS (SHOW TABLES LIKE 'cfgbiz') THEN SELECT siacnotifyto FROM cfgbiz ELSE SELECT '' as siacnotifyto END IF; -and- select IF((SHOW TABLES LIKE