MariaDB [(none)]> use hospital; Database changed MariaDB [hospital]> show tables hospital; 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 'hospital' at line 1 MariaDB [hospital]> show tables ; +----------------------+ | Tables_in_hospital | +----------------------+ | asignaciones_medicos | | ingresos | | medicos | | pacientes | | plantas | +----------------------+ 5 rows in set (0.001 sec) MariaDB [hospital]> select * from medicos; +-----------+----------------------+----------------+------------+-----------------------------+ | id_medico | nombre | especialidad | telefono | Email | +-----------+----------------------+----------------+------------+-----------------------------+ | M001 | Dr. Alejandro Gomez | Cardiologia | 1234567890 | alejandro.gomez@example.com | | M002 | Dra. Sofia Hernandez | Pediatria | 0987654321 | sofia.hernandez@example.com | | M003 | Dr. Luis Martinez | Cirugia | 1122334455 | luis.martinez@example.com | | M004 | Dra. Ana Lopez | Dermatologia | 5566778899 | ana.lopez@example.com | | M005 | Dr. Carlos Diaz | Ortopedia | 9988776655 | carlos.diaz@example.com | | M006 | Dra. Maria Ruiz | Ginecologia | 4433221100 | maria.ruiz@example.com | | M007 | Dr. Pedro Sanchez | Neurologia | 6677889900 | pedro.sanchez@example.com | | M008 | Dra. Laura Fernandez | Oncologia | 3344556677 | laura.fernandez@example.com | | M009 | Dr. Jorge Torres | Psiquiatria | 7788990011 | jorge.torres@example.com | | M010 | Dra. Carmen Garcia | Endocrinologia | 9900112233 | carmen.garcia@example.com | +-----------+----------------------+----------------+------------+-----------------------------+ 10 rows in set (0.029 sec) MariaDB [hospital]> DELIMITER // MariaDB [hospital]> CREATE TRIGGER antes_insertar_paciente AFTER DELETE ON Pacientes FOR EACH ROW -> BEGIN -> DELETE FROM Ingresos WHERE FK_paciente = OLD.id_paciente; -> DELETE FROM Asignaciones_Medicos WHERE FK_ingreso IN (SELECT id_ingreso FROM Ingresos WHERE FK_paciente = OLD.id_paciente); -> END // Query OK, 0 rows affected (0.013 sec) MariaDB [hospital]> DELIMITER ; MariaDB [hospital]> DELETE FROM Pacientes WHERE id_paciente = 'P004'; Query OK, 1 row affected (0.008 sec) MariaDB [hospital]> select * from pacientes; +-------------+-----------------+--------+------------+-----------------------------+ | id_paciente | nombre | genero | telefono | Email | +-------------+-----------------+--------+------------+-----------------------------+ | P001 | Juan Perez | M | 1234567890 | juan.perez@example.com | | P002 | Maria Lopez | F | 0987654321 | maria.lopez@example.com | | P003 | Carlos Sanchez | M | 1122334455 | carlos.sanchez@example.com | | P005 | Luis Garcia | M | 9988776655 | luis.garcia@example.com | | P006 | Sofia Fernandez | F | 4433221100 | sofia.fernandez@example.com | | P007 | Pedro Ramirez | M | 6677889900 | pedro.ramirez@example.com | | P008 | Laura Diaz | F | 3344556677 | laura.diaz@example.com | | P009 | Jorge Ruiz | M | 7788990011 | jorge.ruiz@example.com | | P010 | Carmen Torres | F | 9900112233 | carmen.torres@example.com | +-------------+-----------------+--------+------------+-----------------------------+ 9 rows in set (0.000 sec) MariaDB [hospital]> DELIMITER // MariaDB [hospital]> CREATE TRIGGER genero_paciente BEFORE INSERT ON Pacientes FOR EACH ROW -> BEGIN -> IF NEW.genero NOT IN ('M', 'F') THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'El gOero debe ser "M" o "F"'; -> END IF; -> END // Query OK, 0 rows affected (0.010 sec) MariaDB [hospital]> DELIMITER ; MariaDB [hospital]> select * from pacientes; +-------------+-----------------+--------+------------+-----------------------------+ | id_paciente | nombre | genero | telefono | Email | +-------------+-----------------+--------+------------+-----------------------------+ | P001 | Juan Perez | M | 1234567890 | juan.perez@example.com | | P002 | Maria Lopez | F | 0987654321 | maria.lopez@example.com | | P003 | Carlos Sanchez | M | 1122334455 | carlos.sanchez@example.com | | P005 | Luis Garcia | M | 9988776655 | luis.garcia@example.com | | P006 | Sofia Fernandez | F | 4433221100 | sofia.fernandez@example.com | | P007 | Pedro Ramirez | M | 6677889900 | pedro.ramirez@example.com | | P008 | Laura Diaz | F | 3344556677 | laura.diaz@example.com | | P009 | Jorge Ruiz | M | 7788990011 | jorge.ruiz@example.com | | P010 | Carmen Torres | F | 9900112233 | carmen.torres@example.com | +-------------+-----------------+--------+------------+-----------------------------+ 9 rows in set (0.002 sec) MariaDB [hospital]> INSERT INTO Pacientes (id_paciente, nombre, genero, telefono, Email) VALUES ('P011', 'Juan Perez', 'D', '1234567890', 'juan.perez@example.com'); ERROR 1644 (45000): El gOero debe ser "M" o "F" MariaDB [hospital]> exit