· 5 years ago · Feb 17, 2020, 04:42 PM
1/* DDL */
2create schema if not exists mars;
3
4use mars;
5
6create table if not exists TORN
7 (id int auto_increment primary key,
8 oxigen tinyint unsigned not null default 0,
9 temperatura tinyint not null default -30,
10 oceans tinyint unsigned not null);
11
12create table if not exists TIPUS
13 (nom varchar(50) primary key,
14 descripcio varchar(200));
15
16create table if not exists CORPORACIO
17 (nom varchar(50) primary key,
18 tipus varchar(50) not null,
19 megacredit tinyint unsigned not null,
20 efecte varchar(50),
21 foreign key(tipus) references TIPUS(nom)
22 on delete no action
23 on update cascade);
24
25create table if not exists JUGADOR
26 (nom varchar(50) not null,
27 torn int not null,
28 corporacio varchar(50) not null,
29 PV tinyint unsigned not null default 0,
30 megacredit tinyint unsigned not null default 0,
31 acer tinyint unsigned not null default 0,
32 titani tinyint unsigned not null default 0,
33 vegetals tinyint unsigned not null default 0,
34 energia tinyint unsigned not null default 0,
35 calor tinyint unsigned not null default 0,
36 primary key (nom,torn),
37 foreign key(torn) references TORN(id)
38 on delete no action
39 on update cascade,
40 foreign key(corporacio) references CORPORACIO(nom)
41 on delete no action
42 on update cascade);
43
44 create table if not exists PROJECTE
45 (nom varchar(50) not null primary key,
46 jugador varchar(50) not null,
47 torn int not null,
48 tipus varchar(50),
49 oxigen tinyint unsigned,
50 temperatura tinyint unsigned,
51 oceans tinyint unsigned,
52 PV tinyint unsigned not null default 0,
53 megacredit tinyint unsigned not null default 0,
54 acer tinyint unsigned not null default 0,
55 titani tinyint unsigned not null default 0,
56 vegetals tinyint unsigned not null default 0,
57 energia tinyint unsigned not null default 0,
58 calor tinyint unsigned not null default 0,
59 foreign key(jugador,torn) references JUGADOR(nom,torn)
60 on delete no action
61 on update cascade,
62 foreign key(tipus) references TIPUS(nom)
63 on delete no action
64 on update cascade);
65
66create table if not exists FITA
67 (nom varchar(50) not null primary key,
68 jugador varchar(50) not null,
69 torn int not null,
70 descripcio varchar(200),
71 foreign key(jugador,torn) references JUGADOR(nom,torn)
72 on delete no action
73 on update cascade);
74/*Ejercicios!*/
75
76/*1*/
77INSERT INTO tipus(nom, descripcio) VALUES("edifici", "Descripcio");
78INSERT INTO tipus(nom, descripcio) VALUES("espai", "Descripcio");
79INSERT INTO tipus(nom, descripcio) VALUES("energia", "Descripcio");
80INSERT INTO tipus(nom, descripcio) VALUES("ciencia", "Descripcio");
81INSERT INTO tipus(nom, descripcio) VALUES("jovia", "Descripcio");
82INSERT INTO tipus(nom, descripcio) VALUES("terrestre", "Descripcio");
83INSERT INTO tipus(nom, descripcio) VALUES("ciutat", "Descripcio");
84/*2*/
85INSERT INTO corporacio(nom, tipus, efecte) VALUES("credicor","tipus","efecto");
86INSERT INTO corporacio(nom, tipus, efecte) VALUES("republica tharsis","tipus","efecto");
87INSERT INTO corporacio(nom, tipus, efecte) VALUES("thorgate","tipus","efecto");
88INSERT INTO corporacio(nom, tipus, efecte) VALUES("unmi","tipus","efecto");
89/*3*/
90INSERT INTO jugador(corporacio, torn) VALUES("credicor", "1");
91INSERT INTO jugador(corporacio, torn) VALUES("republica tharsis", "2");
92INSERT INTO jugador(corporacio, torn) VALUES("thorgate", "3");
93INSERT INTO jugador(corporacio, torn) VALUES("unmi", "4");
94
95/*4*/
96
97INSERT INTO jugador(corporacio, torn) VALUES("credicor", "1");
98INSERT INTO jugador(corporacio, torn) VALUES("republica tharsis", "2");
99INSERT INTO jugador(corporacio, torn) VALUES("thorgate", "3");
100INSERT INTO jugador(corporacio, torn) VALUES("unmi", "4");
101
102/*5*/
103
104INSERT INTO jugador(corporacio, torn) VALUES("credicor", "1");
105INSERT INTO jugador(corporacio, torn) VALUES("republica tharsis", "2");
106INSERT INTO jugador(corporacio, torn) VALUES("thorgate", "3");
107INSERT INTO jugador(corporacio, torn) VALUES("unmi", "4");
108
109/*6*/
110
111INSERT INTO jugador(corporacio, torn) VALUES("credicor", "1");
112INSERT INTO jugador(corporacio, torn) VALUES("republica tharsis", "2");
113INSERT INTO jugador(corporacio, torn) VALUES("thorgate", "3");
114INSERT INTO jugador(corporacio, torn) VALUES("unmi", "4");
115
116/*7*/
117INSERT INTO juga(projecte, jugador, torn) VALUES("1", "THORGATE", "2");
118/*8*/
119UPDATE projecte set acer= + 3;
120
121select * from projecte;
122/*9*/
123select * from jugador;
124UPDATE jugador set energia= calor/2;
125/*10*/
126UPDATE torn set temperatura=temperatura+2
127where oxigen>=5;
128select * from torn;
129/*11*/
130UPDATE jugador set pv=pv+4
131where titani>5;
132UPDATE jugador set pv=pv+3
133where titani<=4 and titani > 2;
134UPDATE jugador set pv=pv+1;
135select * from torn;
136/*12*/
137UPDATE jugador set pv=pv+5
138WHERE jugador = thorgate;
139/*13*/
140UPDATE jugador set pv=pv+5;
141/*14*/
142DELETE FROM corporacio WHERE nom = "Thorgate";
143DELETE FROM jugador WHERE corporacio = "Thorgate";
144/*15*/
145DELETE FROM aconsegueix WHERE jugador = "Thorgate";
146/*16*/
147DELETE FROM tipus WHERE nom = "Jovia";
148
149
150
151/*Consultas*/
152
153/*1*/
154select nom from corporacio;
155/*2*/
156/*3*/
157/*4*/
158select * from jugador
159order by PV, corporacio desc;
160/*5*/