BD_ETS.sql 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. DROP DATABASE IF EXISTS `ETS`;
  2. CREATE DATABASE IF NOT EXISTS `ETS`
  3. DEFAULT CHARSET=utf8mb4;
  4. USE `ETS`;
  5. DROP TABLE IF EXISTS `EchedeyLR_Usuarios`;
  6. DROP TABLE IF EXISTS `EchedeyLR_Comentarios`;
  7. CREATE TABLE IF NOT EXISTS `EchedeyLR_Usuarios` (
  8. `Correo` VARCHARACTER(100)
  9. NOT NULL,
  10. `Nombre` VARCHARACTER(20)
  11. NOT NULL,
  12. `Contraseña` VARCHARACTER(128)
  13. NOT NULL,
  14. PRIMARY KEY (`Correo`)
  15. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  16. CREATE TABLE IF NOT EXISTS `EchedeyLR_Comentarios` (
  17. `Correo` VARCHARACTER(100)
  18. NOT NULL,
  19. `Publicación` VARCHARACTER(255)
  20. NOT NULL,
  21. `Tiempo` DATETIME
  22. NOT NULL
  23. DEFAULT NOW(),
  24. `Contenido` TEXT
  25. NOT NULL,
  26. PRIMARY KEY (`Correo`, `Publicación`, `Tiempo`),
  27. FOREIGN KEY(`Correo`)
  28. REFERENCES `EchedeyLR_Usuarios`(`Correo`)
  29. ON UPDATE RESTRICT
  30. ON DELETE RESTRICT
  31. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  32. INSERT INTO `EchedeyLR_Usuarios`
  33. VALUES ("Guest", "Guest", "");
  34. DROP TRIGGER IF EXISTS `AFTER_EchedeyLR_Usuarios_DELETE`;
  35. DELIMITER $$
  36. $$
  37. CREATE DEFINER=`echedey`@`localhost` TRIGGER IF NOT EXISTS `AFTER_EchedeyLR_Usuarios_DELETE`
  38. AFTER DELETE
  39. ON `EchedeyLR_Usuarios`
  40. FOR EACH ROW
  41. BEGIN
  42. UPDATE `EchedeyLR_Comentarios`
  43. SET `Correo` = "Guest"
  44. WHERE `Correo` = OLD.`Correo`;
  45. END$$
  46. DELIMITER ;