Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created July 5, 2019 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/272595e79956db87757f18599ec94560 to your computer and use it in GitHub Desktop.
Save parzibyte/272595e79956db87757f18599ec94560 to your computer and use it in GitHub Desktop.
CREATE TABLE productos(
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
codigo VARCHAR(255) NOT NULL,
descripcion VARCHAR(255) NOT NULL,
precioVenta DECIMAL(5, 2) NOT NULL,
precioCompra DECIMAL(5, 2) NOT NULL,
existencia DECIMAL(5, 2) NOT NULL,
PRIMARY KEY(id)
) ENGINE = InnoDB DEFAULT CHARACTER SET = utf8;
CREATE TABLE ventas(
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
fecha DATETIME NOT NULL,
PRIMARY KEY(id)
) ENGINE = InnoDB DEFAULT CHARACTER SET = utf8;
CREATE TABLE productos_vendidos(
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
id_producto BIGINT UNSIGNED NOT NULL,
cantidad BIGINT UNSIGNED NOT NULL,
precio DECIMAL(5, 2) NOT NULL,
id_venta BIGINT UNSIGNED NOT NULL,
PRIMARY KEY(id),
FOREIGN KEY(id_producto) REFERENCES productos(id) ON DELETE CASCADE,
FOREIGN KEY(id_venta) REFERENCES ventas(id) ON DELETE CASCADE
) ENGINE = InnoDB DEFAULT CHARACTER SET = utf8;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment