MySql - Create view to read from Multiple Tables

前端 未结 2 771
不知归路
不知归路 2021-01-28 18:11

I have archived some old line items for invoices that are no longer current but still need to reference them. I think I need to create a VIEW but not really understanding it. Ca

2条回答
  •  难免孤独
    2021-01-28 18:42

    You can use the MERGE Storage Engine to create a virtual table that's the union of two real tables:

    CREATE TABLE Invoice_LineItem_All 
    (
      `LineItem_ID` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
      `LineItem_ChargeType` VARCHAR(64) NOT NULL DEFAULT '',
      `LineItem_InvoiceID` INT(11) UNSIGNED DEFAULT NULL,
      `LineItem_Amount` DECIMAL(11,4) DEFAULT NULL,
      `LastUpdatedAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
      KEY (`LineItem_ID`),
      KEY `LastUpdatedAt` (`LastUpdatedAt`),
      KEY `LineItem_InvoiceID` (`LineItem_InvoiceID`)
    ) ENGINE=MERGE UNION=(Invoice_LineItem_Archived, Invoice_LineItem);
    

提交回复
热议问题