Bug #50900 Triggers and views error
Submitted: 4 Feb 2010 6:18 Modified: 9 Feb 2010 11:41
Reporter: hamza hamza Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Workbench: Modeling Severity:S1 (Critical)
Version:5.2.15 OS:Any
Assigned to: Alexander Musienko CPU Architecture:Any

[4 Feb 2010 6:18] hamza hamza
Description:
we have a database model with views and triggers

When we run the generated script on mysql we get 

#1046 - No database selected 

we need to add 

USE databasename; 

manually before views and triggers to fix the problem
i think we the program should add this automatically,we know that the triggers Tab show USE databasename as the first line but this line doesn't exists in the generated script

How to repeat:

1- Create this model 

CREATE  TABLE IF NOT EXISTS `mydb`.`table1` (
  `idtable1` INT NOT NULL ,
  PRIMARY KEY (`idtable1`) )
ENGINE = InnoDB;

CREATE  TABLE IF NOT EXISTS `mydb`.`table2` (
  `idtable2` INT NOT NULL ,
  PRIMARY KEY (`idtable2`) )
ENGINE = InnoDB;

CREATE TRIGGER trigger1 AFTER DELETE ON table1
FOR EACH ROW
BEGIN
delete from table2 where idtable2=OLD.idtable1;
END

2- try to generate script and use it on mysql

3- you get the error

4- add 

USE mydb;  

before the trigger in the generated script

5- now the script works

Suggested fix:
we need to add 

USE databasename; 

automatically before views and triggers
[4 Feb 2010 17:35] Johannes Taxacher
fix confirmed
[9 Feb 2010 11:41] Tony Bedford
An entry has been added to the 5.2.16 changelog:

An exported script containing triggers and views resulted in the error #1046 - No database selected when run on the MySQL Server. This was due to a missing USE DATABASE statement in the generated script.