Advertisement
tantarin

tarinskaya_bd_lab2_zad1

May 10th, 2022
626
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- MySQL Script generated by MySQL Workbench
  2. -- Tue May 10 17:00:29 2022
  3. -- Model: New Model    Version: 1.0
  4. -- MySQL Workbench Forward Engineering
  5.  
  6. SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
  7. SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
  8. SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
  9.  
  10. -- -----------------------------------------------------
  11. -- Schema firstModel
  12. -- -----------------------------------------------------
  13.  
  14. -- -----------------------------------------------------
  15. -- Schema firstModel
  16. -- -----------------------------------------------------
  17. CREATE SCHEMA IF NOT EXISTS `firstModel` DEFAULT CHARACTER SET utf8 ;
  18. USE `firstModel` ;
  19.  
  20. -- -----------------------------------------------------
  21. -- Table `firstModel`.`user`
  22. -- -----------------------------------------------------
  23. CREATE TABLE IF NOT EXISTS `firstModel`.`user` (
  24.   `id` INT NOT NULL AUTO_INCREMENT,
  25.   `firstname` VARCHAR(45) NOT NULL,
  26.   `secondname` VARCHAR(45) NOT NULL,
  27.   PRIMARY KEY (`id`))
  28. ENGINE = InnoDB;
  29.  
  30.  
  31. -- -----------------------------------------------------
  32. -- Table `firstModel`.`product`
  33. -- -----------------------------------------------------
  34. CREATE TABLE IF NOT EXISTS `firstModel`.`product` (
  35.   `idproduct` INT NOT NULL,
  36.   `title` VARCHAR(100) NOT NULL,
  37.   `description` TEXT NULL,
  38.   PRIMARY KEY (`idproduct`))
  39. ENGINE = InnoDB;
  40.  
  41.  
  42. -- -----------------------------------------------------
  43. -- Table `firstModel`.`invoice`
  44. -- -----------------------------------------------------
  45. CREATE TABLE IF NOT EXISTS `firstModel`.`invoice` (
  46.   `idinvoice` INT NOT NULL AUTO_INCREMENT,
  47.   `userid` INT NOT NULL,
  48.   `productid` INT NOT NULL,
  49.   `cost` DECIMAL(10,2) NOT NULL,
  50.   PRIMARY KEY (`idinvoice`),
  51.   INDEX `user_idx` (`userid` ASC) VISIBLE,
  52.   INDEX `product_idx` (`productid` ASC) VISIBLE,
  53.   CONSTRAINT `user`
  54.     FOREIGN KEY (`userid`)
  55.     REFERENCES `firstModel`.`user` (`id`)
  56.     ON DELETE CASCADE
  57.     ON UPDATE CASCADE,
  58.   CONSTRAINT `product`
  59.     FOREIGN KEY (`productid`)
  60.     REFERENCES `firstModel`.`product` (`idproduct`)
  61.     ON DELETE CASCADE
  62.     ON UPDATE CASCADE)
  63. ENGINE = InnoDB;
  64.  
  65.  
  66. SET SQL_MODE=@OLD_SQL_MODE;
  67. SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
  68. SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
  69.  
Advertisement
RAW Paste Data Copied
Advertisement