drop database if exists atletski_savez;
create database atletski_savez;
use atletski_savez;

create table takmicenje (
       sifra int primary key,
       naziv varchar(40) not null,
       datum_pocetka date not null
);
create table disciplina (
       sifra int primary key,
       naziv varchar(40) not null,
       rekord smallint default 0
);

create table borba (
       sif_takm int,
       stepen varchar(4) check (stepen in ('I', 'II', 'III', 'IV')),
       sif_discipline int,
       datum date not null,
       rezultat smallint not null check(rezultat between 0 and 100),
       primary key (sif_takm, datum),
       constraint fk_disciplina foreign key (sif_discipline)
		  references disciplina(sifra)
	      on delete cascade,
       constraint fk_takmicenje foreign key (sif_takm)
		  references takmicenje(sifra)
	      on delete cascade
);

alter table disciplina add constraint check(rekord between 0 and 100);
