forked from mestanza/MySQL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproveedores.sql
161 lines (136 loc) · 6.03 KB
/
proveedores.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
-- MySQL Script generated by MySQL Workbench
-- 08/22/16 21:32:03
-- 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 proveedores
-- -----------------------------------------------------
DROP SCHEMA IF EXISTS `proveedores` ;
-- -----------------------------------------------------
-- Schema proveedores
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `proveedores` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
USE `proveedores` ;
-- -----------------------------------------------------
-- Table `proveedores`.`proveedor`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `proveedores`.`proveedor` ;
CREATE TABLE IF NOT EXISTS `proveedores`.`proveedor` (
`rfc_proveedor` VARCHAR(30) NOT NULL COMMENT '',
`nombre` VARCHAR(45) NOT NULL DEFAULT 'Sin nombre' COMMENT '',
`direccion` VARCHAR(80) NOT NULL DEFAULT 'Sin direccion' COMMENT '',
`telefono` VARCHAR(15) NOT NULL DEFAULT 'Sin telefono' COMMENT '',
`pagina_web` VARCHAR(45) NOT NULL DEFAULT 'Sin pagina web' COMMENT '',
PRIMARY KEY (`rfc_proveedor`) COMMENT '')
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `proveedores`.`categoria`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `proveedores`.`categoria` ;
CREATE TABLE IF NOT EXISTS `proveedores`.`categoria` (
`id_categoria` INT NOT NULL COMMENT '',
`nombre` VARCHAR(45) NOT NULL DEFAULT 'Categoria sin nombre' COMMENT '',
`descripcion` VARCHAR(45) NOT NULL DEFAULT 'Sin descripcion' COMMENT '',
PRIMARY KEY (`id_categoria`) COMMENT '')
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `proveedores`.`clientes`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `proveedores`.`clientes` ;
CREATE TABLE IF NOT EXISTS `proveedores`.`clientes` (
`rfc_cliente` VARCHAR(30) NOT NULL COMMENT '',
`nombre` VARCHAR(45) NOT NULL DEFAULT 'Sin nombre' COMMENT '',
`calle` VARCHAR(15) NOT NULL DEFAULT 'Sin calle' COMMENT '',
`numero` VARCHAR(15) NOT NULL DEFAULT 'Sin número' COMMENT '',
`colonia` VARCHAR(20) NOT NULL DEFAULT 'Sin colonia' COMMENT '',
`ciudad` VARCHAR(30) NOT NULL DEFAULT 'Sin ciudad' COMMENT '',
PRIMARY KEY (`rfc_cliente`) COMMENT '')
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `proveedores`.`telefonos_clientes`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `proveedores`.`telefonos_clientes` ;
CREATE TABLE IF NOT EXISTS `proveedores`.`telefonos_clientes` (
`disc` INT NOT NULL COMMENT '',
`rfc_cliente_telefono` VARCHAR(45) NOT NULL COMMENT '',
`telefono` VARCHAR(45) NOT NULL COMMENT '',
PRIMARY KEY (`rfc_cliente_telefono`, `disc`) COMMENT '',
CONSTRAINT `rfc_cliente`
FOREIGN KEY (`rfc_cliente_telefono`)
REFERENCES `proveedores`.`clientes` (`rfc_cliente`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `proveedores`.`producto`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `proveedores`.`producto` ;
CREATE TABLE IF NOT EXISTS `proveedores`.`producto` (
`id_producto` INT NOT NULL COMMENT '',
`precio` FLOAT NOT NULL DEFAULT 0.0 COMMENT '',
`nombre` VARCHAR(45) NOT NULL COMMENT '',
`existencia` VARCHAR(45) NOT NULL COMMENT '',
`id_categoria` INT NOT NULL COMMENT '',
`rfc_proveedor` VARCHAR(30) NOT NULL COMMENT '',
PRIMARY KEY (`id_producto`) COMMENT '',
INDEX `idcategoria_idx` (`id_categoria` ASC) COMMENT '',
INDEX `rfc_proveedor_idx` (`rfc_proveedor` ASC) COMMENT '',
CONSTRAINT `id_categoria`
FOREIGN KEY (`id_categoria`)
REFERENCES `proveedores`.`categoria` (`id_categoria`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `rfc_proveedor`
FOREIGN KEY (`rfc_proveedor`)
REFERENCES `proveedores`.`proveedor` (`rfc_proveedor`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `proveedores`.`venta`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `proveedores`.`venta` ;
CREATE TABLE IF NOT EXISTS `proveedores`.`venta` (
`id_venta` INT NOT NULL COMMENT '',
`fecha_venta` DATE NOT NULL COMMENT '',
`descuento_venta` FLOAT NOT NULL COMMENT '',
`fk_cliente_id` VARCHAR(30) NOT NULL COMMENT '',
PRIMARY KEY (`id_venta`) COMMENT '',
INDEX `rfc_cliente_venta` (`fk_cliente_id` ASC) COMMENT '',
CONSTRAINT `rfc_cliente_venta`
FOREIGN KEY (`fk_cliente_id`)
REFERENCES `proveedores`.`clientes` (`rfc_cliente`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `proveedores`.`detalle_venta`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `proveedores`.`detalle_venta` ;
CREATE TABLE IF NOT EXISTS `proveedores`.`detalle_venta` (
`id_detalle` INT NOT NULL COMMENT '',
`precio_venta` FLOAT NOT NULL COMMENT '',
`cantidad_vendida` INT NOT NULL COMMENT '',
`fk_venta_id` INT NOT NULL COMMENT '',
`fk_producto_id` INT NOT NULL COMMENT '',
PRIMARY KEY (`id_detalle`) COMMENT '',
INDEX `id_venta_detalle_idx` (`fk_venta_id` ASC) COMMENT '',
INDEX `id_producto_idx` (`fk_producto_id` ASC) COMMENT '',
CONSTRAINT `idventas`
FOREIGN KEY (`fk_venta_id`)
REFERENCES `proveedores`.`venta` (`id_venta`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `id_producto`
FOREIGN KEY (`fk_producto_id`)
REFERENCES `proveedores`.`producto` (`id_producto`)
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;
desc clientes;