Está en la página 1de 4

CAMPEONATO DE AJEDREZ

drop database if exists ajedrez;

create database if not exists ajedrez;

use ajedrez;

create table participante(

n_asc int primary key,

nombre varchar(20) ,

telefono varchar(12),

direccion varchar(12),

codigo_p int,

campeonatos varchar(10),

index inx1 (nombre,telefono)

);

create table campeonatos(

n_asc int,

nombre_campeonato varchar(10)

);

alter table campeonatos add constraint pk1

primary key (n_asc,nombre_campeonato);

create table pais(

codigo int primary key,

nombre varchar(10) unique not null,

n_clubs int,

nombre_pais_repr int

);
create table jugador(

n_asc int primary key,

nivel tinyint unsigned default 5

);

create table arbitro(

n_asc int primary key

);

create table if not exists hotel(

nombre varchar(20) primary key,

direccion varchar(30));

create table aloja(

n_hotel varchar(20),

n_asc int,

f_ini date,

f_fin date,

primary key (n_hotel, n_asc, f_ini));

create table sala(

nombre_hotel varchar(20),

nombre_sala varchar(20),

primary key (nombre_hotel,nombre_sala),

recurso set ('radio', 'television', 'vídeo','internet') default null);

create table partida(

id int primary key auto_increment,

j_blancas int,

j_negras int,

constraint ch1 check(j_blancas!=j_negras),

arbitro int,

nombre_hotel varchar(20),

nombre_sala varchar(20),
fecha date);

create table movimiento(

id_partida int,

n_movimiento int,

primary key (id_partida,n_movimiento),

descripcion varchar(5),

comentario varchar(50)

);

Alter table movimiento add constraint fk12 foreign key (id_partida) references

partida(id);

Alter table partida add constraint fk9 foreign key (j_blancas) references

jugador(n_asc);

Alter table partida add constraint fk10 foreign key (j_negras) references

jugador(n_asc);

Alter table partida add constraint fk13 foreign key (arbitro) references

arbitro(n_asc);

Alter table partida add constraint fk11 foreign key (nombre_hotel,nombre_sala) references

sala(nombre_hotel,nombre_sala);

Alter table sala add constraint fk7 foreign key (nombre_hotel) references

hotel(nombre);

Alter table pais add constraint fk1 foreign key (nombre_pais_repr) references

pais(codigo);

Alter table participante add constraint fk2 foreign key (codigo_p)

references pais(codigo);

Alter table jugador add constraint fk3 foreign key (n_asc) references

participante(n_asc);
Alter table arbitro add constraint fk4 foreign key (n_asc) references

participante(n_asc);

Alter table aloja add constraint fk5 foreign key (n_hotel) references

hotel(nombre);

Alter table aloja add constraint fk6 foreign key (n_asc) references

participante(n_asc);

Alter table campeonatos add constraint fk8 foreign key (n_asc) references

participante(n_asc);

También podría gustarte