Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does MySQL Workbench generate placeholder tables for views?

In a database model, I created in MySQL Workbench, I defined a view. When I now generate SQL from the diagramm (Menu -> Database -> Forward Engineer or Ctrl + G), this code is created for my view:

-- -----------------------------------------------------
-- Placeholder table for view `myview`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `myview` (...table columns...);
SHOW WARNINGS;

-- -----------------------------------------------------
-- View `myview`
-- -----------------------------------------------------
DROP VIEW IF EXISTS `myview` ;
SHOW WARNINGS;
DROP TABLE IF EXISTS `myview`;
SHOW WARNINGS;
DELIMITER $$
CREATE OR REPLACE VIEW `myview` AS

...view definition...

$$
DELIMITER ;

;
SHOW WARNINGS;


SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

Why is this placeholder table created?

Thx

like image 705
automatix Avatar asked Mar 14 '13 18:03

automatix


1 Answers

The placeholders are created (not only by WB but also e.g. by mysqldump) to solve circular references. A view definition can refer to a table that requires the view (or a table that requiers a table that requiers a view which finally requires the initial view). This cannot be automatically detected nor solved, except by defining dummy views (temporarily as tables, since views are in most aspects like tables) and then redefining them when all other objects are available.

like image 197
Mike Lischke Avatar answered Nov 17 '22 02:11

Mike Lischke