· 8 years ago · Jan 04, 2018, 05:22 PM
1CREATE TABLE IF NOT EXISTS `mydb`.`order_has_product` (
2 `order_id` INT NOT NULL,
3 `product_id` INT NOT NULL,
4 `amount` INT NOT NULL,
5 `unit_price` DECIMAL(7,2) NOT NULL,
6 `discount` DECIMAL(3,2) NULL,
7 PRIMARY KEY (`order_id`, `product_id`),
8 INDEX `fk_order_has_product_product1_idx` (`product_id` ASC),
9 INDEX `fk_order_has_product_order1_idx` (`order_id` ASC),
10 CONSTRAINT `fk_order_has_product_order1`
11 FOREIGN KEY (`order_id`)
12 REFERENCES `mydb`.`order` (`id`)
13 ON DELETE NO ACTION
14 ON UPDATE NO ACTION,
15 CONSTRAINT `fk_order_has_product_product1`
16 FOREIGN KEY (`product_id`)
17 REFERENCES `mydb`.`product` (`id`)
18 ON DELETE NO ACTION
19 ON UPDATE NO ACTION)
20ENGINE = InnoDB;