-
Notifications
You must be signed in to change notification settings - Fork 0
/
tarea2.sql
114 lines (100 loc) · 3.74 KB
/
tarea2.sql
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
-- MySQL Script generated by MySQL Workbench
-- Sun Apr 16 22:09:36 2023
-- Model: New Model Version: 1.0
-- 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='TRADITIONAL,ALLOW_INVALID_DATES';
-- -----------------------------------------------------
-- Schema tarea2
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema tarea2
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `tarea2` DEFAULT CHARACTER SET utf8 ;
USE `tarea2` ;
-- -----------------------------------------------------
-- Table `tarea2`.`region`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `tarea2`.`region` (
`id` INT NOT NULL AUTO_INCREMENT,
`nombre` VARCHAR(200) NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `tarea2`.`comuna`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `tarea2`.`comuna` (
`id` INT NOT NULL AUTO_INCREMENT,
`nombre` VARCHAR(200) NOT NULL,
`region_id` INT NOT NULL,
PRIMARY KEY (`id`),
INDEX `fk_comuna_region1_idx` (`region_id` ASC),
CONSTRAINT `fk_comuna_region1`
FOREIGN KEY (`region_id`)
REFERENCES `tarea2`.`region` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `tarea2`.`donacion`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `tarea2`.`donacion` (
`id` INT NOT NULL AUTO_INCREMENT,
`comuna_id` INT NOT NULL,
`calle_numero` VARCHAR(80) NULL,
`tipo` ENUM('fruta', 'verdura', 'otro') NOT NULL,
`cantidad` VARCHAR(10) NOT NULL,
`fecha_disponibilidad` TIMESTAMP NOT NULL,
`descripcion` VARCHAR(80) NULL,
`condiciones_retirar` VARCHAR(80) NULL,
`nombre` VARCHAR(80) NOT NULL,
`email` VARCHAR(80) NOT NULL,
`celular` VARCHAR(15) NULL,
PRIMARY KEY (`id`),
INDEX `fk_donacion_comuna1_idx` (`comuna_id` ASC),
CONSTRAINT `fk_donacion_comuna1`
FOREIGN KEY (`comuna_id`)
REFERENCES `tarea2`.`comuna` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `tarea2`.`foto`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `tarea2`.`foto` (
`id` INT NOT NULL AUTO_INCREMENT,
`ruta_archivo` VARCHAR(300) NOT NULL,
`nombre_archivo` VARCHAR(300) NOT NULL,
`donacion_id` INT NOT NULL,
PRIMARY KEY (`id`, `donacion_id`),
INDEX `fk_foto_donacion1_idx` (`donacion_id` ASC),
CONSTRAINT `fk_foto_donacion1`
FOREIGN KEY (`donacion_id`)
REFERENCES `tarea2`.`donacion` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `tarea2`.`pedido`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `tarea2`.`pedido` (
`id` INT NOT NULL AUTO_INCREMENT,
`comuna_id` INT NOT NULL,
`tipo` ENUM('fruta', 'verdura', 'otro') NOT NULL,
`descripcion` VARCHAR(80) NULL,
`cantidad` VARCHAR(10) NOT NULL,
`nombre_solicitante` VARCHAR(80) NOT NULL,
`email_solicitante` VARCHAR(80) NOT NULL,
`celular_solicitante` VARCHAR(15) NULL,
PRIMARY KEY (`id`),
INDEX `fk_pedido_comuna1_idx` (`comuna_id` ASC),
CONSTRAINT `fk_pedido_comuna10`
FOREIGN KEY (`comuna_id`)
REFERENCES `tarea2`.`comuna` (`id`)
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;