-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
67 lines (57 loc) · 2.49 KB
/
schema.sql
File metadata and controls
67 lines (57 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
-- MySQL Workbench Forward Engineering
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
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';
-- -----------------------------------------------------
-- Schema company_inventory
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema company_inventory
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `company_inventory` DEFAULT CHARACTER SET utf8 ;
USE `company_inventory` ;
-- -----------------------------------------------------
-- Table `company_inventory`.`categories`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `company_inventory`.`categories` (
`id_category` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(100) NOT NULL,
PRIMARY KEY (`id_category`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `company_inventory`.`suppliers`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `company_inventory`.`suppliers` (
`id_supplier` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(100) NOT NULL,
`telephone` VARCHAR(20) NULL,
`country` VARCHAR(50) NULL,
PRIMARY KEY (`id_supplier`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `company_inventory`.`products`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `company_inventory`.`products` (
`id_product` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(100) NOT NULL,
`price` DECIMAL(10,2) NOT NULL,
`stock` INT NOT NULL,
`id_category` INT NULL,
`id_supplier` INT NULL,
PRIMARY KEY (`id_product`),
INDEX `id_category_idx` (`id_category` ASC) VISIBLE,
INDEX `id_supplier_idx` (`id_supplier` ASC) VISIBLE,
CONSTRAINT `id_category`
FOREIGN KEY (`id_category`)
REFERENCES `company_inventory`.`categories` (`id_category`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `id_supplier`
FOREIGN KEY (`id_supplier`)
REFERENCES `company_inventory`.`suppliers` (`id_supplier`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;