jueves, 7 de octubre de 2010

CODIGO DE LA BASE DE DATOS

create database corrida;
show databases;
use corrida;
show tables;
create table corrida (
id_corrida tinyint(3) not null,
num_orden tinyint(3) not null,
feria char(30) not null,
ano year not null, primary key (id_corrida))engine=innodb;

create table apoderado (
id_apoderado tinyint(3) not null,
rfc char(10) not null,
nombre char(50) not null,
direccion char(40) not null,
telefono char(15), primary key (id_apoderado))engine=innodb;

create table plazas (
id_plazas tinyint(3) not null,
nombre char(30) not null,
localidad char(20) not null,
direccion char(40) not null,
aforo int, primary key (id_plazas))engine=innodb;

create table ganaderia (
id_ganaderia tinyint(3) not null,
codigo char(15) not null,
localidad char(30) not null,
antiguedad date, primary key (id_ganaderia))engine=innodb;

create table premios (
id_premios tinyint(3) not null,
orejas tinyint(3),
rabo tinyint(3),
puerta_grande bool not null, primary key (id_premios))engine=innodb;

create table torero (
id_torero tinyint(3) not null,
id_apoderado tinyint(3) not null,
rfc char(10) not null,
nombre char(50),
apodo char(15) not null,
padrino bool not null, primary key (id_torero),
index(id_apoderado),
foreign key (id_apoderado) references apoderado (id_apoderado) on delete set null on update restrict)engine=innodb;

create table padrino (
fecha_matador date not null,
id_torero tinyint(3) not null,
index (id_torero),
foreign key (id_torero) references torero (id_torero) on delete cascade on update cascade)engine=innodb;

create table toros(
num_orden tinyint(3) not null,
id_ganaderia tinyiint(3) not null,
ano_nac year,
nombre char(20) not null,
color char(10),
orden_toreado tinyint(3) not null,
index (id_ganaderia),
foreign key (id_ganaderia) references ganaderia (id_ganaderia) on delete set null on update restrict)engine=innodb;

create table fiestas(
num_orden tinyint(3) not null,
index (num_orden),
foreign key (num_orden) references toros (num_orden) on delete cascade on update cascade,
id_plazas tinyint(3),
index (id_plazas),
foreign key (id_plazas) references plazas (id_plazas) on delete set null on update restrict,
id_torero tinyint(3),
index (id_torero),
foreign key (id_torero) references torero (id_torero) on delete set null on update cascade,
id_corrida tinyint(3) not null,
index (id_corrida),
foreign key (id_corrida) references corrida (id_corrida) on delete cascade on update cascade)engine=innodb;

create table premio_torero(
id_premios tinyint(3) not null,
index (id_premios),
foreign key (id_premios) references premios (id_premios) on delete cascade on update restrict,
id_torero tinyint(3) not null,
index (id_torero),
foreign key (id_torero) references torero (id_torero) on delete cascade on update restrict,
id_corrida tinyint(3) not null,
index (id_corrida),
foreign key (id_corrida) references corrida (id_corrida) on delete cascade on update cascade)engine=innodb;

No hay comentarios:

Publicar un comentario