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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With