Mini sistema de facturación - Creación de la base de datos y tablas

Debemos tener instalado XAMPP u otro paquete para administrar nuestro servidor web Apache, lenguaje PHP y gestor de bases de datos MySQL.

Utilizaremos el programa PhpMyAdmin para crear la base de datos: 'base1':

Creación de la base de datos con PhpMyAdmin

Seguidamente, luego de seleccionar la base de datos 'base1' procedemos a crear las tablas 'categorias', 'productos', 'clientes', 'facturas' y 'detallefactura' con algunos datos de prueba

Para crear las tablas y los datos de prueba puede ejecutar el siguiente conjunto de comandos SQL:


DROP TABLE IF EXISTS `categorias`;

CREATE TABLE `categorias` (
  `codigo` int(11) NOT NULL AUTO_INCREMENT,
  `descripcion` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`codigo`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

/*Data for the table `categorias` */

insert into `categorias` values 

(1,'Microprocesadores'),

(2,'Discos Sólidos SSD'),

(3,'Placas De Video');

/*Table structure for table `clientes` */

DROP TABLE IF EXISTS `clientes`;

CREATE TABLE `clientes` (
  `codigo` int(11) NOT NULL AUTO_INCREMENT,
  `nombre` varchar(50) DEFAULT NULL,
  `telefono` varchar(20) DEFAULT NULL,
  `mail` varchar(70) DEFAULT NULL,
  `direccion` varchar(70) DEFAULT NULL,
  PRIMARY KEY (`codigo`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

/*Data for the table `clientes` */

insert into `clientes` values 

(1,'Diego Martinez','23567892','diegomartinez@gmail.com','Colon 345'),

(2,'Ana Paula','64345664','anapaula@gmail.com','Dean Funes 345'),

(3,'Marcos Rodriguez','65984384','marcosrodriguez@gmail.com','23 de septiembre 3444');

/*Table structure for table `detallefactura` */

DROP TABLE IF EXISTS `detallefactura`;

CREATE TABLE `detallefactura` (
  `codigo` int(11) NOT NULL AUTO_INCREMENT,
  `codigofactura` int(11) DEFAULT NULL,
  `codigoproducto` int(11) DEFAULT NULL,
  `precio` float DEFAULT NULL,
  `cantidad` int(11) DEFAULT NULL,
  PRIMARY KEY (`codigo`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=latin1;

/*Data for the table `detallefactura` */

insert into `detallefactura` values 

(1,1,3,17800,1),

(2,1,6,2199,1),

(3,1,7,20995,1),

(4,2,1,3499,1),

(5,2,5,1595,1),

(6,3,4,23999,1),

(7,3,6,2199,1),

(8,3,8,30000,1),

(9,4,4,23999,1),

(10,4,5,1595,2);

/*Table structure for table `facturas` */

DROP TABLE IF EXISTS `facturas`;

CREATE TABLE `facturas` (
  `codigo` int(11) NOT NULL AUTO_INCREMENT,
  `fecha` date DEFAULT NULL,
  `codigocliente` int(11) DEFAULT NULL,
  PRIMARY KEY (`codigo`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

/*Data for the table `facturas` */

insert into `facturas` values 

(1,'2019-10-29',1),

(2,'2019-10-29',2),

(3,'2019-10-29',3),

(4,'2019-10-29',1);

/*Table structure for table `productos` */

DROP TABLE IF EXISTS `productos`;

CREATE TABLE `productos` (
  `codigo` int(11) NOT NULL AUTO_INCREMENT,
  `descripcion` varchar(50) DEFAULT NULL,
  `precio` float DEFAULT NULL,
  `codigocategoria` int(11) DEFAULT NULL,
  PRIMARY KEY (`codigo`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;

/*Data for the table `productos` */

insert into `productos` values 

(1,'Intel celeron g4900 2/2 3.1ghz',3499,1),

(2,'Intel core i3 9100f coffeelake',6245,1),

(3,'Intel core i5 9600k',17800,1),

(4,'Intel core i7 8700 coffee lake',23999,1),

(5,'ssd 120gb wd green',1595,2),

(6,'ssd 240gb wd green sata iii 2.5',2199,2),

(7,'nvidia geforce gtx 1660ti',20995,3),

(8,'nvidia geforce rtx 2060 6gb',30000,3);

Debemos seleccionar la pestaña "SQL" de PhpMyAdmin y pegar el código anterior, estando seleccionada la base de datos "base1":

Creación de las tablas del proyecto de facturación PhpMyAdmin