-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhomework1.sql
More file actions
227 lines (188 loc) · 7.74 KB
/
homework1.sql
File metadata and controls
227 lines (188 loc) · 7.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
-- phpMyAdmin SQL Dump
-- version 5.1.1
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Creato il: Mag 28, 2022 alle 15:36
-- Versione del server: 10.4.20-MariaDB
-- Versione PHP: 7.4.21
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `homework1`
--
-- --------------------------------------------------------
--
-- Struttura della tabella `comments_for_posts`
--
CREATE TABLE `comments_for_posts` (
`user` varchar(255) NOT NULL,
`post_id` int(11) NOT NULL,
`comment` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dump dei dati per la tabella `comments_for_posts`
--
INSERT INTO `comments_for_posts` (`user`, `post_id`, `comment`) VALUES
('matteosan', 13, 'Fede tu saresti capace di rifiutare tranquillamente un 30! :D'),
('matteosan', 6, 'Da non dimenticare il ping pong, passavo un sacco di tempo a giocare a ping pong in Apple!'),
('Schembra00', 14, 'Bravo Matteo! ');
--
-- Trigger `comments_for_posts`
--
DELIMITER $$
CREATE TRIGGER `INCREASE_NUM_COMMENTS` AFTER INSERT ON `comments_for_posts` FOR EACH ROW UPDATE posts
SET num_comments = num_comments + 1
WHERE id = new.post_id
$$
DELIMITER ;
-- --------------------------------------------------------
--
-- Struttura della tabella `likes_for_posts`
--
CREATE TABLE `likes_for_posts` (
`id_like` int(11) NOT NULL,
`user` varchar(255) NOT NULL,
`post_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dump dei dati per la tabella `likes_for_posts`
--
INSERT INTO `likes_for_posts` (`id_like`, `user`, `post_id`) VALUES
(19, 'Schembra00', 6),
(20, 'Conc00', 7),
(23, 'matteosan', 7),
(27, 'FedeNic', 7),
(28, 'FedeNic', 13),
(29, 'matteosan', 13),
(30, 'matteosan', 6),
(31, 'matteosan', 14),
(32, 'matteosan', 15),
(33, 'GiusMalg', 6);
--
-- Trigger `likes_for_posts`
--
DELIMITER $$
CREATE TRIGGER `DECREASE_NUM_LIKES` AFTER DELETE ON `likes_for_posts` FOR EACH ROW UPDATE posts
SET num_likes = num_likes - 1
WHERE id = old.post_id
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `INCREASE_NUM_LIKES` AFTER INSERT ON `likes_for_posts` FOR EACH ROW UPDATE posts
SET num_likes = num_likes + 1
WHERE id = new.post_id
$$
DELIMITER ;
-- --------------------------------------------------------
--
-- Struttura della tabella `posts`
--
CREATE TABLE `posts` (
`id` int(11) NOT NULL,
`title` varchar(255) NOT NULL,
`content` varchar(1200) NOT NULL,
`username` varchar(255) NOT NULL,
`num_likes` int(11) DEFAULT NULL,
`num_comments` int(11) DEFAULT NULL,
`publish_date` date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dump dei dati per la tabella `posts`
--
INSERT INTO `posts` (`id`, `title`, `content`, `username`, `num_likes`, `num_comments`, `publish_date`) VALUES
(6, 'I dipendenti di Amazon, Apple programmano tutto il giorno?', 'Ho lavorato ad Amazon per 2 anni e mezzo. La mia giornata tipo era:Arrivavo alle 11,Caffè/tè e chiaccherata coi colleghi per 15/20 minuti.Tornavo al lavoro e rispondevo alle mail. Facevo chiamate per dare aggiornamenti sui miei task giornalieri.\r\nLeggevo le documentazioni oppure codice.', 'Schembra00', 3, 1, '2022-05-27'),
(7, 'Cos\'è l\'Al Norman? La Prima Intelligenza Artificiale Psicopatica ', 'Un team del Massachusetts Institute ha creato un algoritmo chiamato Norman, tratto dal film \"Psycho\" di Hitchcock e lo ha addestrato a considerare il mondo come un posto sempre violento. Al software sono state mostrate immagini di persone che morivano in maniera violenta, al limite del gore. ', 'Conc00', 3, 0, '2022-05-27'),
(13, 'È possibile rifiutare un 30 ad un esame universitario?', 'L\'ho visto fare, ad una mia amica. Analisi II, che già solo a passarlo dovevi accendere un cero, almeno trent\'anni fa.\r\n\r\nLa professoressa era ovviamente contrariata, ma diede comunque una chance. Disse che avrebbe fatto un\'ulteriore domanda. Se andava bene, c\'era la lode, se andava male, andava a casa senza esame, cosa che la mia amica avrebbe fatto comunque.', 'FedeNic', 2, 1, '2022-05-28'),
(14, 'Il 5G è dannoso per la salute?', 'È stato dimostrato che la radiazione a onde millimetriche a 60,42 GHz e con una densità di potenza incidente massima di 1 mW/cm2 non altera la vitalità cellulare, l\'espressione genica e la conformazione delle proteine. Quindi neanche nelle condizioni più sfavorevoli risulta dannoso.', 'matteosan', 1, 1, '2022-05-28'),
(15, 'Cos\'è il deep learning? Come funziona?', 'La traduzione strettamente letterale di questo termine, di chiara matrice anglosassone, è apprendimento approfondito. Ed è proprio questo il centro del suo significato, perché il deep learning, sottocategoria del Machine Learning, non fa altro che creare modelli di apprendimento su più livelli.', 'matteosan', 1, 0, '2022-05-28');
-- --------------------------------------------------------
--
-- Struttura della tabella `users`
--
CREATE TABLE `users` (
`name` varchar(255) NOT NULL,
`lastname` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`username` varchar(255) NOT NULL,
`password` varchar(16) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dump dei dati per la tabella `users`
--
INSERT INTO `users` (`name`, `lastname`, `email`, `username`, `password`) VALUES
('Spampinato', 'Concetto', 'concetto.spampinato@outlook.it', 'Conc00', 'Serpente01'),
('ee', 'eee', 'eeee@gmail.com', 'eee', 'Serpente01'),
('Federico', 'Nicotra', 'federico.nicotra@gmail.com', 'FedeNic', 'Serpente01'),
('Giuseppe', 'Malgeri', 'giuseppe.malgeri@unict.it', 'GiusMalg', 'Serpente01'),
('Matteo', 'Santanocito', 'mattsantanocito@gmail.com', 'matteosan', 'Serpente01'),
('Schembra', 'Giovanni', 'schembra.giovanni@tiscali.it', 'Schembra00', 'Serpente01'),
('Volodymyr ', 'Zelenskyj', 'volodymyr.zelenskyj@saveuckraine.it', 'Zele1978', 'Serpente01');
--
-- Indici per le tabelle scaricate
--
--
-- Indici per le tabelle `comments_for_posts`
--
ALTER TABLE `comments_for_posts`
ADD KEY `post_id` (`post_id`);
--
-- Indici per le tabelle `likes_for_posts`
--
ALTER TABLE `likes_for_posts`
ADD PRIMARY KEY (`id_like`),
ADD KEY `user` (`user`),
ADD KEY `post_id` (`post_id`);
--
-- Indici per le tabelle `posts`
--
ALTER TABLE `posts`
ADD PRIMARY KEY (`id`),
ADD KEY `username` (`username`);
--
-- Indici per le tabelle `users`
--
ALTER TABLE `users`
ADD PRIMARY KEY (`username`),
ADD UNIQUE KEY `email` (`email`);
--
-- AUTO_INCREMENT per le tabelle scaricate
--
--
-- AUTO_INCREMENT per la tabella `likes_for_posts`
--
ALTER TABLE `likes_for_posts`
MODIFY `id_like` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=34;
--
-- AUTO_INCREMENT per la tabella `posts`
--
ALTER TABLE `posts`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=16;
--
-- Limiti per le tabelle scaricate
--
--
-- Limiti per la tabella `comments_for_posts`
--
ALTER TABLE `comments_for_posts`
ADD CONSTRAINT `comments_for_posts_ibfk_1` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`) ON DELETE CASCADE;
--
-- Limiti per la tabella `likes_for_posts`
--
ALTER TABLE `likes_for_posts`
ADD CONSTRAINT `likes_for_posts_ibfk_1` FOREIGN KEY (`user`) REFERENCES `users` (`username`) ON DELETE CASCADE,
ADD CONSTRAINT `likes_for_posts_ibfk_2` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`) ON DELETE CASCADE;
--
-- Limiti per la tabella `posts`
--
ALTER TABLE `posts`
ADD CONSTRAINT `posts_ibfk_1` FOREIGN KEY (`username`) REFERENCES `users` (`username`) ON DELETE CASCADE;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;