I'm trying to create a mySQL Script file, so i can easily execute my changes in differente databases, but I'm having problems with a IF statement. (I'm using MySQL Workbench).
CREATE TABLE IF NOT EXISTS `build` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Version` varchar(20) NOT NULL,
`Date` datetime DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
IF EXISTS(select 1 from build where Versao = '1.1') THEN select "yes";
The create table sentence is executed correctly, but the "IF Exists(select..." statement is giving the following error:
SYNTAX ERROR: IF (if) is not a valid input at this position
The select "Yes" command will actually be replaced by an insert command. I'm just trying to test if the IF command will work.
I've also tried to put the IF EXISTS(select line in a separated query, but had the same result.
What am I doing wrong?