Microsoft Windows [Versión 10.0.22621.2134] (c) Microsoft Corporation. Todos los derechos reservados. C:\Users\Harold Martinez>cd/xampp/mysql/bin C:\xampp\mysql\bin>mysql -uroot -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 17 Server version: 10.4.24-MariaDB mariadb.org binary distribution Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> source D:\Descargas\ejer_subconsultas.sql Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Database changed Query OK, 0 rows affected (0.003 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.005 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.002 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.004 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.006 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.001 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.003 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.006 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.002 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.003 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.005 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.001 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) MariaDB [facturacion]> show tables; +-----------------------+ | Tables_in_facturacion | +-----------------------+ | cliente | | clientetotal | | detallado | | detallefactura | | factura | | producto | +-----------------------+ 6 rows in set (0.001 sec) MariaDB [facturacion]> select * from producto; Empty set (0.001 sec) MariaDB [facturacion]> select * from cliente; Empty set (0.001 sec) MariaDB [facturacion]> select * from detalle factura; ERROR 1146 (42S02): Table 'facturacion.detalle' doesn't exist MariaDB [facturacion]> select * from detallefactura; Empty set (0.000 sec) MariaDB [facturacion]> insert into cliente(cedula, nombre, direccion, fechainicio) values(100,'alexandralopez','aranjuez','2003-12-03'); Query OK, 1 row affected (0.002 sec) MariaDB [facturacion]> insert into cliente(cedula, nombre, direccion, fechainicio) values(200,'sebastianperez','sabaneta','2005-07-17'); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into cliente(cedula, nombre, direccion, fechainicio) values(300,'saraherrera','floresta','2007-09-20'); Query OK, 1 row affected (0.002 sec) MariaDB [facturacion]> insert into cliente(cedula, nombre, direccion, fechainicio) values(400,'luisaroldan','floresta','2009-10-15'); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into cliente(cedula, nombre, direccion, fechainicio) values(500,'mariohenao','bello','2004-02-28'); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into cliente(cedula, nombre, direccion, fechainicio) values(600,'luisacifuentes','florencia','2003-09-01'); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into cliente(cedula, nombre, direccion, fechainicio) values(700,'edithgarcia','envigado','2006-03-03'); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into cliente(cedula, nombre, direccion, fechainicio) values(800,'claudialainez','itag','2005-04-13'); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into cliente(cedula, nombre, direccion, fechainicio) values(900,'vivianpiedrahita','centro','2006-01-19'); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into factura(nrofactura, cedula, subtotal, iva, retencion, total) values(2002,300,0,0,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into factura(nrofactura, cedula, subtotal, iva, retencion, total) values(3003,200,0,0,0,0); Query OK, 1 row affected (0.002 sec) MariaDB [facturacion]> insert into factura(nrofactura, cedula, subtotal, iva, retencion, total) values(4004,400,0,0,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into factura(nrofactura, cedula, subtotal, iva, retencion, total) values(5005,200,0,0,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into factura(nrofactura, cedula, subtotal, iva, retencion, total) values(6006,500,0,0,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into factura(nrofactura, cedula, subtotal, iva, retencion, total) values(7007,100,0,0,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into factura(nrofactura, cedula, subtotal, iva, retencion, total) values(8008,400,0,0,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into factura(nrofactura, cedula, subtotal, iva, retencion, total) values(9009,400,0,0,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into factura(nrofactura, cedula, subtotal, iva, retencion, total) values(1101,600,0,0,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into factura(nrofactura, cedula, subtotal, iva, retencion, total) values(2202,700,0,0,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into factura(nrofactura, cedula, subtotal, iva, retencion, total) values(3303,600,0,0,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into factura(nrofactura, cedula, subtotal, iva, retencion, total) values(4404,100,0,0,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into factura(nrofactura, cedula, subtotal, iva, retencion, total) values(5505,700,0,0,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into factura(nrofactura, cedula, subtotal, iva, retencion, total) values(6606,800,0,0,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into factura(nrofactura, cedula, subtotal, iva, retencion, total) values(7707,900,0,0,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into factura(nrofactura, cedula, subtotal, iva, retencion, total) values(8808,800,0,0,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into factura(nrofactura, cedula, subtotal, iva, retencion, total) values(9909,900,0,0,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into producto(codigo, articulo, valorunitario, cantidad, valorventa, existencia) values('20','auricules',75000,27,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into producto(codigo, articulo, valorunitario, cantidad, valorventa, existencia) values('30','mp3',150000,24,0,0); Query OK, 1 row affected (0.002 sec) MariaDB [facturacion]> insert into producto(codigo, articulo, valorunitario, cantidad, valorventa, existencia) values('40','mouse',25000,33,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into producto(codigo, articulo, valorunitario, cantidad, valorventa, existencia) values('50','taclado',130000,45,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into producto(codigo, articulo, valorunitario, cantidad, valorventa, existencia) values('60','discoduro',203000,17,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into producto(codigo, articulo, valorunitario, cantidad, valorventa, existencia) values('70','unidaddvd',250000,19,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into producto(codigo, articulo, valorunitario, cantidad, valorventa, existencia) values('80','usb',80000,28,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into producto(codigo, articulo, valorunitario, cantidad, valorventa, existencia) values('90','lapizoptico',134000,17,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(1,1001,'10',1,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(2,1001,'40',2,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(3,1001,'70',1,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(4,2002,'60',2,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(5,3003,'20',4,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(6,3003,'80',1,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(7,4004,'10',2,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(8,4004,'20',1,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(9,4004,'30',1,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(10,4004,'60',1,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(11,4004,'70',1,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(12,4004,'80',2,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(13,5005,'10',3,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(14,6006,'20',1,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(15,6006,'80',2,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(16,6006,'30',2,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(17,6006,'90',2,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(18,6006,'50',1,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(19,6006,'40',2,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(20,7007,'10',1,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(21,7007,'90',2,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(22,8008,'60',2,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(23,8008,'40',2,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(24,8008,'50',1,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(25,9009,'50',2,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(26,9009,'80',1,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(27,1101,'30',1,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(28,2202,'30',2,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(29,1101,'60',1,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(30,3303,'60',2,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(31,4404,'90',3,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(32,5505,'80',4,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(33,6606,'70',2,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(34,7707,'10',1,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(35,8808,'40',2,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(36,9909,'20',3,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(37,9909,'30',4,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(38,6606,'50',5,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(39,7707,'40',1,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> insert into detallefactura(id, nrofactura, codigo, cantidad, valor, total) values(40,1101,'30',1,0,0); Query OK, 1 row affected (0.001 sec) MariaDB [facturacion]> select * from cliente; +--------+------------------+-----------+-------------+ | cedula | nombre | direccion | fechainicio | +--------+------------------+-----------+-------------+ | 100 | alexandralopez | aranjuez | 2003-12-03 | | 200 | sebastianperez | sabaneta | 2005-07-17 | | 300 | saraherrera | floresta | 2007-09-20 | | 400 | luisaroldan | floresta | 2009-10-15 | | 500 | mariohenao | bello | 2004-02-28 | | 600 | luisacifuentes | florencia | 2003-09-01 | | 700 | edithgarcia | envigado | 2006-03-03 | | 800 | claudialainez | itag | 2005-04-13 | | 900 | vivianpiedrahita | centro | 2006-01-19 | +--------+------------------+-----------+-------------+ 9 rows in set (0.001 sec) MariaDB [facturacion]> select * from factura; +------------+--------+----------+-----+-----------+-------+ | nrofactura | cedula | subtotal | iva | retencion | total | +------------+--------+----------+-----+-----------+-------+ | 1001 | 100 | 0 | 0 | 0 | 0 | | 1101 | 600 | 0 | 0 | 0 | 0 | | 2002 | 300 | 0 | 0 | 0 | 0 | | 2202 | 700 | 0 | 0 | 0 | 0 | | 3003 | 200 | 0 | 0 | 0 | 0 | | 3303 | 600 | 0 | 0 | 0 | 0 | | 4004 | 400 | 0 | 0 | 0 | 0 | | 4404 | 100 | 0 | 0 | 0 | 0 | | 5005 | 200 | 0 | 0 | 0 | 0 | | 5505 | 700 | 0 | 0 | 0 | 0 | | 6006 | 500 | 0 | 0 | 0 | 0 | | 6606 | 800 | 0 | 0 | 0 | 0 | | 7007 | 100 | 0 | 0 | 0 | 0 | | 7707 | 900 | 0 | 0 | 0 | 0 | | 8008 | 400 | 0 | 0 | 0 | 0 | | 8808 | 800 | 0 | 0 | 0 | 0 | | 9009 | 400 | 0 | 0 | 0 | 0 | | 9909 | 900 | 0 | 0 | 0 | 0 | +------------+--------+----------+-----+-----------+-------+ 18 rows in set (0.000 sec) MariaDB [facturacion]> select * from producto; +--------+-------------+---------------+----------+------------+------------+ | codigo | articulo | valorunitario | cantidad | valorventa | existencia | +--------+-------------+---------------+----------+------------+------------+ | 10 | tv | 1250000 | 22 | 0 | 0 | | 20 | auricules | 75000 | 27 | 0 | 0 | | 30 | mp3 | 150000 | 24 | 0 | 0 | | 40 | mouse | 25000 | 33 | 0 | 0 | | 50 | taclado | 130000 | 45 | 0 | 0 | | 60 | discoduro | 203000 | 17 | 0 | 0 | | 70 | unidaddvd | 250000 | 19 | 0 | 0 | | 80 | usb | 80000 | 28 | 0 | 0 | | 90 | lapizoptico | 134000 | 17 | 0 | 0 | +--------+-------------+---------------+----------+------------+------------+ 9 rows in set (0.000 sec) MariaDB [facturacion]> select * from detallefactura; +------+------------+--------+----------+-------+-------+ | id | nrofactura | codigo | cantidad | valor | total | +------+------------+--------+----------+-------+-------+ | 0001 | 1001 | 10 | 1 | 0 | 0 | | 0002 | 1001 | 40 | 2 | 0 | 0 | | 0003 | 1001 | 70 | 1 | 0 | 0 | | 0004 | 2002 | 60 | 2 | 0 | 0 | | 0005 | 3003 | 20 | 4 | 0 | 0 | | 0006 | 3003 | 80 | 1 | 0 | 0 | | 0007 | 4004 | 10 | 2 | 0 | 0 | | 0008 | 4004 | 20 | 1 | 0 | 0 | | 0009 | 4004 | 30 | 1 | 0 | 0 | | 0010 | 4004 | 60 | 1 | 0 | 0 | | 0011 | 4004 | 70 | 1 | 0 | 0 | | 0012 | 4004 | 80 | 2 | 0 | 0 | | 0013 | 5005 | 10 | 3 | 0 | 0 | | 0014 | 6006 | 20 | 1 | 0 | 0 | | 0015 | 6006 | 80 | 2 | 0 | 0 | | 0016 | 6006 | 30 | 2 | 0 | 0 | | 0017 | 6006 | 90 | 2 | 0 | 0 | | 0018 | 6006 | 50 | 1 | 0 | 0 | | 0019 | 6006 | 40 | 2 | 0 | 0 | | 0020 | 7007 | 10 | 1 | 0 | 0 | | 0021 | 7007 | 90 | 2 | 0 | 0 | | 0022 | 8008 | 60 | 2 | 0 | 0 | | 0023 | 8008 | 40 | 2 | 0 | 0 | | 0024 | 8008 | 50 | 1 | 0 | 0 | | 0025 | 9009 | 50 | 2 | 0 | 0 | | 0026 | 9009 | 80 | 1 | 0 | 0 | | 0027 | 1101 | 30 | 1 | 0 | 0 | | 0028 | 2202 | 30 | 2 | 0 | 0 | | 0029 | 1101 | 60 | 1 | 0 | 0 | | 0030 | 3303 | 60 | 2 | 0 | 0 | | 0031 | 4404 | 90 | 3 | 0 | 0 | | 0032 | 5505 | 80 | 4 | 0 | 0 | | 0033 | 6606 | 70 | 2 | 0 | 0 | | 0034 | 7707 | 10 | 1 | 0 | 0 | | 0035 | 8808 | 40 | 2 | 0 | 0 | | 0036 | 9909 | 20 | 3 | 0 | 0 | | 0037 | 9909 | 30 | 4 | 0 | 0 | | 0038 | 6606 | 50 | 5 | 0 | 0 | | 0039 | 7707 | 40 | 1 | 0 | 0 | | 0040 | 1101 | 30 | 1 | 0 | 0 | +------+------------+--------+----------+-------+-------+ 40 rows in set (0.001 sec) MariaDB [facturacion]> delimiter // MariaDB [facturacion]> create trigger actvalor after insert on producto -> for each row -> begin -> Update detallefactura set valor = (select valorventa from producto where codigo = detallefactura.codigo); -> end -> // Query OK, 0 rows affected (0.005 sec) MariaDB [facturacion]> delimiter ; MariaDB [facturacion]> show triggers; +----------+--------+----------+---------------------------------------------------------------------------------------------------------------------+--------+------------------------+-----------------------------------------------------+----------------+----------------------+----------------------+--------------------+ | Trigger | Event | Table | Statement | Timing | Created | sql_mode | Definer | character_set_client | collation_connection | Database Collation | +----------+--------+----------+---------------------------------------------------------------------------------------------------------------------+--------+------------------------+-----------------------------------------------------+----------------+----------------------+----------------------+--------------------+ | actvalor | INSERT | producto | begin Update detallefactura set valor = (select valorventa from producto where codigo = detallefactura.codigo); end | AFTER | 2023-08-21 16:05:41.58 | NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION | root@localhost | cp850 | cp850_general_ci | utf8_general_ci | +----------+--------+----------+---------------------------------------------------------------------------------------------------------------------+--------+------------------------+-----------------------------------------------------+----------------+----------------------+----------------------+--------------------+ 1 row in set (0.004 sec) MariaDB [facturacion]> insert into producto(codigo, articulo, valorunitario, cantidad, valorventa, existencia) values('11','computador',900000,15,0,0); Query OK, 1 row affected (0.005 sec) MariaDB [facturacion]> select * from detallefactura; +------+------------+--------+----------+---------+-------+ | id | nrofactura | codigo | cantidad | valor | total | +------+------------+--------+----------+---------+-------+ | 0001 | 1001 | 10 | 1 | 1462500 | 0 | | 0002 | 1001 | 40 | 2 | 29250 | 0 | | 0003 | 1001 | 70 | 1 | 292500 | 0 | | 0004 | 2002 | 60 | 2 | 237510 | 0 | | 0005 | 3003 | 20 | 4 | 87750 | 0 | | 0006 | 3003 | 80 | 1 | 93600 | 0 | | 0007 | 4004 | 10 | 2 | 1462500 | 0 | | 0008 | 4004 | 20 | 1 | 87750 | 0 | | 0009 | 4004 | 30 | 1 | 175500 | 0 | | 0010 | 4004 | 60 | 1 | 237510 | 0 | | 0011 | 4004 | 70 | 1 | 292500 | 0 | | 0012 | 4004 | 80 | 2 | 93600 | 0 | | 0013 | 5005 | 10 | 3 | 1462500 | 0 | | 0014 | 6006 | 20 | 1 | 87750 | 0 | | 0015 | 6006 | 80 | 2 | 93600 | 0 | | 0016 | 6006 | 30 | 2 | 175500 | 0 | | 0017 | 6006 | 90 | 2 | 156780 | 0 | | 0018 | 6006 | 50 | 1 | 152100 | 0 | | 0019 | 6006 | 40 | 2 | 29250 | 0 | | 0020 | 7007 | 10 | 1 | 1462500 | 0 | | 0021 | 7007 | 90 | 2 | 156780 | 0 | | 0022 | 8008 | 60 | 2 | 237510 | 0 | | 0023 | 8008 | 40 | 2 | 29250 | 0 | | 0024 | 8008 | 50 | 1 | 152100 | 0 | | 0025 | 9009 | 50 | 2 | 152100 | 0 | | 0026 | 9009 | 80 | 1 | 93600 | 0 | | 0027 | 1101 | 30 | 1 | 175500 | 0 | | 0028 | 2202 | 30 | 2 | 175500 | 0 | | 0029 | 1101 | 60 | 1 | 237510 | 0 | | 0030 | 3303 | 60 | 2 | 237510 | 0 | | 0031 | 4404 | 90 | 3 | 156780 | 0 | | 0032 | 5505 | 80 | 4 | 93600 | 0 | | 0033 | 6606 | 70 | 2 | 292500 | 0 | | 0034 | 7707 | 10 | 1 | 1462500 | 0 | | 0035 | 8808 | 40 | 2 | 29250 | 0 | | 0036 | 9909 | 20 | 3 | 87750 | 0 | | 0037 | 9909 | 30 | 4 | 175500 | 0 | | 0038 | 6606 | 50 | 5 | 152100 | 0 | | 0039 | 7707 | 40 | 1 | 29250 | 0 | | 0040 | 1101 | 30 | 1 | 175500 | 0 | +------+------------+--------+----------+---------+-------+ 40 rows in set (0.001 sec) MariaDB [facturacion]> select * from factura; +------------+--------+----------+-----+-----------+-------+ | nrofactura | cedula | subtotal | iva | retencion | total | +------------+--------+----------+-----+-----------+-------+ | 1001 | 100 | 0 | 0 | 0 | 0 | | 1101 | 600 | 0 | 0 | 0 | 0 | | 2002 | 300 | 0 | 0 | 0 | 0 | | 2202 | 700 | 0 | 0 | 0 | 0 | | 3003 | 200 | 0 | 0 | 0 | 0 | | 3303 | 600 | 0 | 0 | 0 | 0 | | 4004 | 400 | 0 | 0 | 0 | 0 | | 4404 | 100 | 0 | 0 | 0 | 0 | | 5005 | 200 | 0 | 0 | 0 | 0 | | 5505 | 700 | 0 | 0 | 0 | 0 | | 6006 | 500 | 0 | 0 | 0 | 0 | | 6606 | 800 | 0 | 0 | 0 | 0 | | 7007 | 100 | 0 | 0 | 0 | 0 | | 7707 | 900 | 0 | 0 | 0 | 0 | | 8008 | 400 | 0 | 0 | 0 | 0 | | 8808 | 800 | 0 | 0 | 0 | 0 | | 9009 | 400 | 0 | 0 | 0 | 0 | | 9909 | 900 | 0 | 0 | 0 | 0 | +------------+--------+----------+-----+-----------+-------+ 18 rows in set (0.001 sec) MariaDB [facturacion]> Update detallefactura set total = cantidad * valor; Query OK, 40 rows affected (0.001 sec) Rows matched: 40 Changed: 40 Warnings: 0 MariaDB [facturacion]> delimiter // MariaDB [facturacion]> create trigger actsubtotal after insert on producto -> for each row -> begin -> Update factura set subtotal = (select sum(total) from detallefactura where nrofactura = factura.nrofactura); -> end -> // Query OK, 0 rows affected (0.005 sec) MariaDB [facturacion]> show triggers; -> delimiter ; -> // +-------------+--------+----------+------------------------------------------------------------------------------------------------------------------------+--------+------------------------+-----------------------------------------------------+----------------+----------------------+----------------------+--------------------+ | Trigger | Event | Table | Statement | Timing | Created | sql_mode | Definer | character_set_client | collation_connection | Database Collation | +-------------+--------+----------+------------------------------------------------------------------------------------------------------------------------+--------+------------------------+-----------------------------------------------------+----------------+----------------------+----------------------+--------------------+ | actvalor | INSERT | producto | begin Update detallefactura set valor = (select valorventa from producto where codigo = detallefactura.codigo); end | AFTER | 2023-08-21 16:05:41.58 | NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION | root@localhost | cp850 | cp850_general_ci | utf8_general_ci | | actsubtotal | INSERT | producto | begin Update factura set subtotal = (select sum(total) from detallefactura where nrofactura = factura.nrofactura); end | AFTER | 2023-08-21 16:12:40.76 | NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION | root@localhost | cp850 | cp850_general_ci | utf8_general_ci | +-------------+--------+----------+------------------------------------------------------------------------------------------------------------------------+--------+------------------------+-----------------------------------------------------+----------------+----------------------+----------------------+--------------------+ 2 rows in set (0.003 sec) ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'delimiter' at line 1 MariaDB [facturacion]> insert into producto(codigo, articulo, valorunitario, cantidad, valorventa, existencia) values('12','Ipad Air',3000000,23,0,0); -> // Query OK, 1 row affected (0.005 sec) MariaDB [facturacion]> delimiter ; MariaDB [facturacion]> select * from factura; +------------+--------+----------+-----+-----------+-------+ | nrofactura | cedula | subtotal | iva | retencion | total | +------------+--------+----------+-----+-----------+-------+ | 1001 | 100 | 1813500 | 0 | 0 | 0 | | 1101 | 600 | 588510 | 0 | 0 | 0 | | 2002 | 300 | 475020 | 0 | 0 | 0 | | 2202 | 700 | 351000 | 0 | 0 | 0 | | 3003 | 200 | 444600 | 0 | 0 | 0 | | 3303 | 600 | 475020 | 0 | 0 | 0 | | 4004 | 400 | 3905460 | 0 | 0 | 0 | | 4404 | 100 | 470340 | 0 | 0 | 0 | | 5005 | 200 | 4387500 | 0 | 0 | 0 | | 5505 | 700 | 374400 | 0 | 0 | 0 | | 6006 | 500 | 1150110 | 0 | 0 | 0 | | 6606 | 800 | 1345500 | 0 | 0 | 0 | | 7007 | 100 | 1776060 | 0 | 0 | 0 | | 7707 | 900 | 1491750 | 0 | 0 | 0 | | 8008 | 400 | 685620 | 0 | 0 | 0 | | 8808 | 800 | 58500 | 0 | 0 | 0 | | 9009 | 400 | 397800 | 0 | 0 | 0 | | 9909 | 900 | 965250 | 0 | 0 | 0 | +------------+--------+----------+-----+-----------+-------+ 18 rows in set (0.001 sec) MariaDB [facturacion]> exit Bye C:\xampp\mysql\bin>mysqldump -B -uroot --routines facturacion>c:/xampp/facturacion.sql C:\xampp\mysql\bin>