Shaun Mccran

My digital playground

05
D
E
C
2008

MySQL does not support conditional if/else scripts unless its compiled

I've recently changed companies, and as a consequence changed some toolsets. One of these is a switch from MS SQL to MY SQL. Its an interesting learning curve, and I'm trying to stay open minded, but I really did quite like MS SQL....

I have a series of scripts that I have built over the years, they perform standard functions like creating tables, alters creating stored procs etc... (will post soon!). They are all self checking, and output nice processing messages to tell the user whats going on.

So I embarked on a mission to convert these to MY SQL. My first stumbling block was not referencing the master table form MS SQL, as it doesn't exist in MY SQL, but handily there is something similar.

view plain print about
1SELECT count(*)
2FROM information_schema.tables
3WHERE table_schema = DBName
4AND table_name = tableName

The problem then comes with evaluating this result into an IF statement. It turns out that MY SQL cannot process IF-ELSE conditionals unless it is within a compiled script, like a stored proceedure.

Bit of a show stopper there! So now I am trying to find another way to check for the existence of database objects.

TweetBacks
Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Back to top