Advertisement
Bostion

ESIII - AP3 - Schema

Apr 3rd, 2022
1,264
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE TABLE `arma` (
  2.     `id` int NOT NULL AUTO_INCREMENT,
  3.     `nome` varchar(50) NOT NULL,
  4.     `tipo` varchar(50) NOT NULL,
  5.     `id_crime` int,
  6.     PRIMARY KEY (`id`)
  7. );
  8.  
  9. CREATE TABLE `crime` (
  10.     `id` int NOT NULL AUTO_INCREMENT,
  11.     `tipo` varchar(50) NOT NULL,
  12.     `data_hora` DATETIME NOT NULL,
  13.     `local` varchar(50) NOT NULL,
  14.     PRIMARY KEY (`id`)
  15. );
  16.  
  17. CREATE TABLE `criminoso` (
  18.     `id` int NOT NULL AUTO_INCREMENT,
  19.     `nome` varchar(100) NOT NULL AUTO_INCREMENT,
  20.     `foto` varchar(150) NOT NULL AUTO_INCREMENT,
  21.     `cpf` varchar(14),
  22.     PRIMARY KEY (`id`)
  23. );
  24.  
  25. CREATE TABLE `crime_criminoso` (
  26.     `id` int NOT NULL AUTO_INCREMENT,
  27.     `id_crime` int NOT NULL,
  28.     `id_criminoso` int NOT NULL,
  29.     PRIMARY KEY (`id`)
  30. );
  31.  
  32. CREATE TABLE `vitima` (
  33.     `id` int NOT NULL AUTO_INCREMENT,
  34.     `nome` int NOT NULL AUTO_INCREMENT,
  35.     `cpf` varchar(14) NOT NULL,
  36.     PRIMARY KEY (`id`)
  37. );
  38.  
  39. CREATE TABLE `crime_vitima` (
  40.     `id` int NOT NULL AUTO_INCREMENT,
  41.     `id_crime` int NOT NULL,
  42.     `id_vitima` int NOT NULL,
  43.     PRIMARY KEY (`id`)
  44. );
  45.  
  46. ALTER TABLE `arma` ADD CONSTRAINT `arma_fk0` FOREIGN KEY (`id_crime`) REFERENCES `crime`(`id`);
  47.  
  48. ALTER TABLE `crime_criminoso` ADD CONSTRAINT `crime_criminoso_fk0` FOREIGN KEY (`id_crime`) REFERENCES `crime`(`id`);
  49.  
  50. ALTER TABLE `crime_criminoso` ADD CONSTRAINT `crime_criminoso_fk1` FOREIGN KEY (`id_criminoso`) REFERENCES `criminoso`(`id`);
  51.  
  52. ALTER TABLE `crime_vitima` ADD CONSTRAINT `crime_vitima_fk0` FOREIGN KEY (`id_crime`) REFERENCES `crime`(`id`);
  53.  
  54. ALTER TABLE `crime_vitima` ADD CONSTRAINT `crime_vitima_fk1` FOREIGN KEY (`id_vitima`) REFERENCES `vitima`(`id`);
  55.  
Advertisement
RAW Paste Data Copied
Advertisement