· 6 years ago · Dec 09, 2019, 12:26 PM
1create table if not exists Gruppo
2(id_gruppo int not null AUTO_INCREMENT,
3 anno_di_fondazione date not null,
4 nome varchar(30),
5 primary key (id_gruppo));
6
7
8
9create table if not exists Luogo
10(id_luogo int not null AUTO_INCREMENT,
11 nome varchar(30) not null,
12 indirizzo varchar(30) not null,
13 primary key (id_luogo));
14
15
16
17create table if not exists Concerto
18(id_concerto int not null AUTO_INCREMENT,
19 data date not null,
20 fk_id_luogo int,
21 primary key (id_concerto),
22 CONSTRAINT fk_id_luogo
23 foreign key (fk_id_luogo) REFERENCES luogo(id_luogo)
24 on delete no action
25 on update no action);
26
27
28
29create table if not exists ruolo
30(id_ruolo int not null AUTO_INCREMENT,
31 tipo varchar(30),
32 PRIMARY KEY(id_ruolo));
33
34
35
36create table if not exists componente
37(id_componente int not null AUTO_INCREMENT,
38 nome varchar(30) not null,
39 cognome varchar(30) not null,
40 nazionalità varchar(30) not null,
41 anno_di_nascita date not null,
42 fk_componenti int,
43 fk_gruppo int,
44 PRIMARY key(id_componente),
45 CONSTRAINT fk_componente
46 foreign key (fk_componenti) references ruolo(id_ruolo)
47 on delete cascade
48 on update cascade,
49 CONSTRAINT fk_gruppo
50 foreign key (fk_gruppo) REFERENCES gruppo(id_gruppo)
51 on delete no action
52 on update no action);
53
54
55
56create table if not exists album
57(codice_album int not null AUTO_INCREMENT,
58 anno date not null,
59 titolo varchar(30) not null,
60 fk_gruppo int,
61 primary key(codice_album),
62 CONSTRAINT fk_gruppi
63 FOREIGN KEY(fk_gruppo) REFERENCES gruppo(id_gruppo)
64 on delete no action
65 on update no action);