· 5 years ago · Mar 02, 2020, 09:10 PM
1Drop schema if exists eleccions_ud4;
2create schema eleccions_ud4 charset utf8 collate utf8_spanish_ci;
3use eleccions_ud4;
4
5create table candidato (
6idlista integer not null auto_increment,
7posicion integer not null,
8can_nome varchar(40) null,
9primary key (idlista, posicion)
10) engine = innodb;
11
12create table circunscricion (
13id integer not null auto_increment primary key,
14cir_nome varchar(40) not null,
15cir_censo integer not null,
16cir_deputados integer not null,
17cir_vemitidos integer null,
18cir_vbranco integer null,
19cir_vnulos integer null,
20cir_idcomunidade integer null
21) engine = innodb;
22
23create table comunidade (
24id integer not null auto_increment primary key,
25com_nome varchar(59) not null,
26com_poboacion integer not null,
27com_censo integer not null
28) engine = innodb;
29
30create table lista (
31id integer not null auto_increment primary key,
32lis_vobtidos integer not null,
33lis_deputados decimal (4,0) null,
34lis_idpartido integer not null,
35lis_idcir integer not null
36) engine = innodb;
37
38create table partido (
39id integer not null auto_increment primary key,
40par_nome varchar(40) not null,
41par_siglas varchar(40) not null,
42par_afiliados integer null
43) engine = innodb;
44
45alter table candidato
46add foreing key (idlista) references id (lista);
47
48alter table circunscricion
49add foreing key (cir_idcomunidade) references comunidade (id);
50
51alter table lista
52add foreing key (lis_idcir) references circunscricion (id);