Microsoft Windows [Versión 10.0.26200.7840] (c) Microsoft Corporation. Todos los derechos reservados. C:\Users\Hp>cd c:\xampp\mysql\bin c:\xampp\mysql\bin>mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 8 Server version: 10.4.32-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)]> use cine_gestion; Database changed MariaDB [cine_gestion]> show tables; +------------------------+ | Tables_in_cine_gestion | +------------------------+ | boleto | | cliente | | detalle_venta | | empleado | | funcion | | pelicula | | sala | | snack | | venta_snack | +------------------------+ 9 rows in set (0.001 sec) MariaDB [cine_gestion]> select * from boleto; +-----------+------------+------------+--------+---------+ | id_boleto | id_funcion | id_cliente | precio | asiento | +-----------+------------+------------+--------+---------+ | 1 | 1 | 1 | 5.50 | A1 | | 2 | 2 | 2 | 4.00 | B2 | | 3 | 3 | 3 | 6.00 | C3 | | 4 | 4 | 4 | 5.00 | D4 | | 5 | 5 | 5 | 4.50 | E5 | | 6 | 6 | 6 | 6.50 | F6 | | 7 | 7 | 7 | 5.25 | G7 | | 8 | 8 | 8 | 5.75 | H8 | | 9 | 9 | 9 | 6.00 | I9 | | 10 | 10 | 10 | 4.25 | J10 | +-----------+------------+------------+--------+---------+ 10 rows in set (0.075 sec) MariaDB [cine_gestion]> select * from cliente; +------------+----------------+--------------------+-----------+ | id_cliente | nombre | correo | telefono | +------------+----------------+--------------------+-----------+ | 1 | Juan Pérez | juan@example.com | 123456789 | | 2 | Maria López | maria@example.com | 987654321 | | 3 | Pedro Martínez | pedro@example.com | 456789123 | | 4 | Lucia Gómez | lucia@example.com | 321654987 | | 5 | Carlos Ruiz | carlos@example.com | 789123456 | | 6 | Ana Torres | ana@example.com | 654321789 | | 7 | Luis Castro | luis@example.com | 147258369 | | 8 | Laura Díaz | laura@example.com | 963852741 | | 9 | Diego Herrera | diego@example.com | 852741963 | | 10 | Carmen Salas | carmen@example.com | 741852963 | +------------+----------------+--------------------+-----------+ 10 rows in set (0.012 sec) MariaDB [cine_gestion]> select * from detalle_venta; +------------+----------+----------+----------+----------+ | id_detalle | id_venta | id_snack | cantidad | subtotal | +------------+----------+----------+----------+----------+ | 1 | 1 | 1 | 1 | 2.50 | | 2 | 1 | 2 | 1 | 1.50 | | 3 | 2 | 3 | 2 | 6.00 | | 4 | 3 | 4 | 2 | 3.50 | | 5 | 4 | 5 | 2 | 4.50 | | 6 | 5 | 6 | 1 | 3.50 | | 7 | 6 | 7 | 3 | 3.00 | | 8 | 7 | 8 | 4 | 5.00 | | 9 | 8 | 9 | 1 | 2.00 | | 10 | 9 | 10 | 2 | 2.00 | +------------+----------+----------+----------+----------+ 10 rows in set (0.040 sec) MariaDB [cine_gestion]> select * from empleado; +-------------+-----------------+----------------+-------------------+-----------+ | id_empleado | nombre | cargo | correo | telefono | +-------------+-----------------+----------------+-------------------+-----------+ | 1 | Jorge Mendoza | Cajero | jorge@cine.com | 123456789 | | 2 | Sofia Rojas | Taquillera | sofia@cine.com | 987654321 | | 3 | Elena Vargas | Vigilancia | elena@cine.com | 456789123 | | 4 | Mario Cifuentes | Proyeccionista | mario@cine.com | 321654987 | | 5 | Gabriela Medina | Limpieza | gabriela@cine.com | 789123456 | | 6 | Oscar Robles | Gerente | oscar@cine.com | 654321789 | | 7 | Camila Suárez | Vendedora | camila@cine.com | 147258369 | | 8 | Daniel Acosta | Auxiliar | daniel@cine.com | 963852741 | | 9 | Raquel Silva | Supervisora | raquel@cine.com | 852741963 | | 10 | José Torres | Cocinero | jose@cine.com | 741852963 | +-------------+-----------------+----------------+-------------------+-----------+ 10 rows in set (0.003 sec) MariaDB [cine_gestion]> select * from funcion; +------------+-------------+---------+------------+----------+ | id_funcion | id_pelicula | id_sala | fecha | hora | +------------+-------------+---------+------------+----------+ | 1 | 1 | 1 | 2025-05-30 | 18:00:00 | | 2 | 2 | 2 | 2025-05-30 | 16:00:00 | | 3 | 3 | 3 | 2025-05-30 | 20:00:00 | | 4 | 4 | 4 | 2025-05-30 | 14:00:00 | | 5 | 5 | 5 | 2025-05-31 | 17:30:00 | | 6 | 6 | 6 | 2025-05-31 | 19:00:00 | | 7 | 7 | 7 | 2025-05-31 | 15:00:00 | | 8 | 8 | 8 | 2025-05-31 | 13:00:00 | | 9 | 9 | 9 | 2025-05-31 | 21:00:00 | | 10 | 10 | 10 | 2025-05-31 | 12:00:00 | +------------+-------------+---------+------------+----------+ 10 rows in set (0.013 sec) MariaDB [cine_gestion]> select * from pelicula; +-------------+-------------------+-----------+----------+---------------+ | id_pelicula | titulo | genero | duracion | clasificacion | +-------------+-------------------+-----------+----------+---------------+ | 1 | Avengers: Endgame | Acción | 180 | PG-13 | | 2 | Toy Story 4 | Animación | 100 | G | | 3 | Joker | Drama | 122 | R | | 4 | Frozen II | Animación | 103 | PG | | 5 | The Lion King | Aventura | 118 | PG | | 6 | Parasite | Suspenso | 132 | R | | 7 | 1917 | Bélica | 119 | R | | 8 | Ford v Ferrari | Deportes | 152 | PG-13 | | 9 | Aladdin | Fantasía | 128 | PG | | 10 | Knives Out | Misterio | 130 | PG-13 | +-------------+-------------------+-----------+----------+---------------+ 10 rows in set (0.016 sec) MariaDB [cine_gestion]> select * from sala; +---------+---------+-----------+ | id_sala | nombre | capacidad | +---------+---------+-----------+ | 1 | Sala 1 | 100 | | 2 | Sala 2 | 80 | | 3 | Sala 3 | 120 | | 4 | Sala 4 | 90 | | 5 | Sala 5 | 110 | | 6 | Sala 6 | 70 | | 7 | Sala 7 | 130 | | 8 | Sala 8 | 85 | | 9 | Sala 9 | 95 | | 10 | Sala 10 | 100 | +---------+---------+-----------+ 10 rows in set (0.012 sec) MariaDB [cine_gestion]> select * from snack; +----------+-----------+--------+ | id_snack | nombre | precio | +----------+-----------+--------+ | 1 | Palomitas | 2.50 | | 2 | Refresco | 1.50 | | 3 | Nachos | 3.00 | | 4 | Chocolate | 1.75 | | 5 | Hot Dog | 2.25 | | 6 | Pizza | 3.50 | | 7 | Agua | 1.00 | | 8 | Galletas | 1.25 | | 9 | Helado | 2.00 | | 10 | Maní | 1.00 | +----------+-----------+--------+ 10 rows in set (0.013 sec) MariaDB [cine_gestion]> select * from venta_snack; +----------+-------------+------------+------------+-------+ | id_venta | id_empleado | id_cliente | fecha | total | +----------+-------------+------------+------------+-------+ | 1 | 1 | 1 | 2025-05-30 | 4.00 | | 2 | 2 | 2 | 2025-05-30 | 6.50 | | 3 | 3 | 3 | 2025-05-30 | 5.25 | | 4 | 4 | 4 | 2025-05-31 | 7.00 | | 5 | 5 | 5 | 2025-05-31 | 6.00 | | 6 | 6 | 6 | 2025-05-31 | 3.75 | | 7 | 7 | 7 | 2025-05-31 | 8.00 | | 8 | 8 | 8 | 2025-05-31 | 2.50 | | 9 | 9 | 9 | 2025-05-31 | 4.25 | | 10 | 10 | 10 | 2025-05-31 | 5.50 | +----------+-------------+------------+------------+-------+ 10 rows in set (0.013 sec) MariaDB [cine_gestion]> delimiter // MariaDB [cine_gestion]> create trigger calcular_subtotal -> after inseert on detalle_venta -> for each row -> begin -> update detalle_venta -> set subtotal = (select precio from snack where snack.id_snack = detalle_venta.id_snack) * cantidad -> where id_detalle = new.id_detalle; -> end // 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 'inseert on detalle_venta for each row begin update detalle_venta set subtotal...' at line 2 MariaDB [cine_gestion]> create trigger calcular_subtotal -> after insert on detalle_venta -> for each row -> begin -> update detalle_venta -> set subtotal = (select precio from snack where snack.id_snack = detalle_venta.id_snack) * cantidad -> where id_detalle = new.id_detalle; -> end // Query OK, 0 rows affected (0.006 sec) MariaDB [cine_gestion]> delimiter ; MariaDB [cine_gestion]> show triggers; +-------------------+--------+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------+------------------------+-----------------------------------------------------+----------------+----------------------+----------------------+--------------------+ | Trigger | Event | Table | Statement | Timing | Created | sql_mode | Definer | character_set_client | collation_connection | Database Collation | +-------------------+--------+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------+------------------------+-----------------------------------------------------+----------------+----------------------+----------------------+--------------------+ | calcular_subtotal | INSERT | detalle_venta | begin update detalle_venta set subtotal = (select precio from snack where snack.id_snack = detalle_venta.id_snack) * cantidad where id_detalle = new.id_detalle; end | AFTER | 2026-03-12 21:50:14.52 | NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION | root@localhost | cp850 | cp850_general_ci | utf8mb4_general_ci | +-------------------+--------+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------+------------------------+-----------------------------------------------------+----------------+----------------------+----------------------+--------------------+ 1 row in set (0.025 sec) MariaDB [cine_gestion]> delimiter // MariaDB [cine_gestion]> create trigger actualizar_total -> after insert on detalle_venta -> for each row -> begin -> update venta_snack -> set total = total + new.subtotal -> where id -> \c MariaDB [cine_gestion]> create trigger actualizar_total -> after insert on detalle_venta -> for each row -> begin -> update venta_snack -> set total = total + new.subtotal -> where id_venta = new.id_venta; -> end // Query OK, 0 rows affected (0.045 sec) MariaDB [cine_gestion]> show triggers; -> \c MariaDB [cine_gestion]> delimiter ; MariaDB [cine_gestion]> show triggers; +-------------------+--------+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------+------------------------+-----------------------------------------------------+----------------+----------------------+----------------------+--------------------+ | Trigger | Event | Table | Statement | Timing | Created | sql_mode | Definer | character_set_client | collation_connection | Database Collation | +-------------------+--------+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------+------------------------+-----------------------------------------------------+----------------+----------------------+----------------------+--------------------+ | calcular_subtotal | INSERT | detalle_venta | begin update detalle_venta set subtotal = (select precio from snack where snack.id_snack = detalle_venta.id_snack) * cantidad where id_detalle = new.id_detalle; end | AFTER | 2026-03-12 21:50:14.52 | NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION | root@localhost | cp850 | cp850_general_ci | utf8mb4_general_ci | | actualizar_total | INSERT | detalle_venta | begin update venta_snack set total = total + new.subtotal where id_venta = new.id_venta; end | AFTER | 2026-03-12 21:56:32.15 | NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION | root@localhost | cp850 | cp850_general_ci | utf8mb4_general_ci | +-------------------+--------+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------+------------------------+-----------------------------------------------------+----------------+----------------------+----------------------+--------------------+ 2 rows in set (0.051 sec) MariaDB [cine_gestion]> select * from detalle_venta; +------------+----------+----------+----------+----------+ | id_detalle | id_venta | id_snack | cantidad | subtotal | +------------+----------+----------+----------+----------+ | 1 | 1 | 1 | 1 | 2.50 | | 2 | 1 | 2 | 1 | 1.50 | | 3 | 2 | 3 | 2 | 6.00 | | 4 | 3 | 4 | 2 | 3.50 | | 5 | 4 | 5 | 2 | 4.50 | | 6 | 5 | 6 | 1 | 3.50 | | 7 | 6 | 7 | 3 | 3.00 | | 8 | 7 | 8 | 4 | 5.00 | | 9 | 8 | 9 | 1 | 2.00 | | 10 | 9 | 10 | 2 | 2.00 | +------------+----------+----------+----------+----------+ 10 rows in set (0.002 sec) MariaDB [cine_gestion]> INSERT INTO detalle_venta (id_venta,id_snack,cantidad,subtotal) -> VALUES (1,1,2,0); ERROR 1442 (HY000): Can't update table 'detalle_venta' in stored function/trigger because it is already used by statement which invoked this stored function/trigger MariaDB [cine_gestion]> drop trigger calcular_subtotal; Query OK, 0 rows affected (0.042 sec) MariaDB [cine_gestion]> INSERT INTO detalle_venta (id_venta,id_snack,cantidad,subtotal) VALUES (1,1,2,5); Query OK, 1 row affected (0.003 sec) MariaDB [cine_gestion]> select * from detalle_venta; +------------+----------+----------+----------+----------+ | id_detalle | id_venta | id_snack | cantidad | subtotal | +------------+----------+----------+----------+----------+ | 1 | 1 | 1 | 1 | 2.50 | | 2 | 1 | 2 | 1 | 1.50 | | 3 | 2 | 3 | 2 | 6.00 | | 4 | 3 | 4 | 2 | 3.50 | | 5 | 4 | 5 | 2 | 4.50 | | 6 | 5 | 6 | 1 | 3.50 | | 7 | 6 | 7 | 3 | 3.00 | | 8 | 7 | 8 | 4 | 5.00 | | 9 | 8 | 9 | 1 | 2.00 | | 10 | 9 | 10 | 2 | 2.00 | | 12 | 1 | 1 | 2 | 5.00 | +------------+----------+----------+----------+----------+ 11 rows in set (0.000 sec) MariaDB [cine_gestion]> use cine_gestion; Database changed MariaDB [cine_gestion]> exit Bye