-- phpMyAdmin SQL Dump
-- version 4.1.14
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: May 06, 2017 at 04:57 PM
-- Server version: 5.6.17
-- PHP Version: 5.5.12

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `maratonac2017`
--
CREATE DATABASE IF NOT EXISTS `maratonac2017` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
USE `maratonac2017`;

-- --------------------------------------------------------

--
-- Table structure for table `dogadjaji`
--

DROP TABLE IF EXISTS `dogadjaji`;
CREATE TABLE IF NOT EXISTS `dogadjaji` (
  `id` int(12) NOT NULL AUTO_INCREMENT,
  `naziv` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  `zemlja` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  `datum` date NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=11 ;

--
-- Dumping data for table `dogadjaji`
--

INSERT INTO `dogadjaji` (`id`, `naziv`, `zemlja`, `datum`) VALUES
(1, 'Beogradski maraton 2017', 'Srbija', '2017-04-22'),
(2, 'Kopaonik 2017', 'Srbija', '2017-06-10'),
(3, 'Berlin Marathon 2017', 'Nemacka', '2017-09-30'),
(4, 'Marathon filed', 'Grcka', '2017-06-24'),
(5, 'Novosadski maraton', 'Srbija', '2017-05-06'),
(6, 'Blackwater', 'Irska', '2017-05-21'),
(7, 'Strawberry race', 'Irska', '2017-05-28'),
(8, 'Worlds End 2017', 'Ujedinjeno kraljevstvo', '2017-05-27'),
(9, 'London Marathon 2017', 'Ujedinjeno kraljevstvo', '2017-04-23'),
(10, 'Lincoln', 'Ujedinjeno kraljevstvo', '2017-05-06');

-- --------------------------------------------------------

--
-- Table structure for table `korisnici`
--

DROP TABLE IF EXISTS `korisnici`;
CREATE TABLE IF NOT EXISTS `korisnici` (
  `kor_ime` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  `lozinka` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  `ime` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  `prezime` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  `tip` tinyint(1) NOT NULL COMMENT '0 - organizator, 1 - trkač',
  PRIMARY KEY (`kor_ime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Dumping data for table `korisnici`
--

INSERT INTO `korisnici` (`kor_ime`, `lozinka`, `ime`, `prezime`, `tip`) VALUES
('amela', 'sifra123', 'Amela', 'Terzic', 1),
('bosko', 'sifra123', 'Bosko', 'Nikolic', 0),
('dennis', 'sifra123', 'Dennis', 'Kimetto', 1),
('drazen', 'sifra123', 'Drazen', 'Draskovic', 1),
('dudas', 'sifra123', 'Mihail', 'Dudas', 1),
('jecika', 'sifra123', 'Jelena', 'Markovic', 1),
('marko', 'sifra123', 'Marko', 'Markovic', 1),
('maryk', 'sifra123', 'Mary', 'Keitany', 1),
('milana', 'sifra123', 'Milana', 'Milosevic', 1),
('olivera', 'sifra123', 'Olivera', 'Jevtic', 1),
('perica', 'sifra123', 'Petar', 'Petrovic', 1),
('sanja', 'sifra123', 'Sanja', 'Delcev', 1),
('ubolt', 'sifra123', 'Usein', 'Bolt', 1);

-- --------------------------------------------------------

--
-- Table structure for table `rezultati`
--

DROP TABLE IF EXISTS `rezultati`;
CREATE TABLE IF NOT EXISTS `rezultati` (
  `id` int(12) NOT NULL AUTO_INCREMENT,
  `trkac` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  `trka` int(12) NOT NULL,
  `vreme` time DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `trkac` (`trkac`,`trka`),
  KEY `trkac_2` (`trkac`),
  KEY `trka` (`trka`),
  KEY `trkac_3` (`trkac`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=45 ;

--
-- Dumping data for table `rezultati`
--

INSERT INTO `rezultati` (`id`, `trkac`, `trka`, `vreme`) VALUES
(1, 'drazen', 3, '01:57:43'),
(2, 'amela', 1, '00:13:21'),
(3, 'olivera', 2, '01:23:45'),
(4, 'dudas', 2, '01:13:31'),
(5, 'sanja', 1, '00:20:14'),
(6, 'maryk', 3, '02:18:31'),
(7, 'dennis', 3, '02:03:04'),
(8, 'perica', 3, '03:43:12'),
(9, 'ubolt', 1, '00:10:15'),
(10, 'milana', 2, '02:31:11'),
(11, 'jecika', 2, '02:31:10'),
(12, 'milana', 7, NULL),
(13, 'maryk', 6, NULL),
(14, 'milana', 9, NULL),
(15, 'jecika', 9, NULL),
(16, 'sanja', 12, NULL),
(17, 'drazen', 7, NULL),
(18, 'maryk', 8, NULL),
(19, 'dennis', 8, NULL),
(21, 'maryk', 17, '02:17:01'),
(22, 'drazen', 16, '02:15:09'),
(24, 'olivera', 17, '03:15:21'),
(25, 'marko', 15, '01:21:00'),
(26, 'sanja', 15, '01:43:10'),
(27, 'dennis', 17, '02:10:21'),
(28, 'dudas', 15, '00:51:47'),
(29, 'olivera', 16, '01:40:12'),
(30, 'perica', 16, '02:55:02'),
(31, 'amela', 15, '00:59:12'),
(33, 'marko', 17, '04:12:21'),
(34, 'ubolt', 16, '01:45:01'),
(35, 'maryk', 5, NULL),
(36, 'dennis', 5, NULL),
(37, 'dudas', 5, NULL),
(38, 'amela', 5, NULL),
(39, 'ubolt', 5, NULL),
(40, 'olivera', 14, NULL),
(41, 'marko', 14, NULL),
(42, 'drazen', 14, NULL),
(43, 'sanja', 14, NULL),
(44, 'perica', 14, NULL);

-- --------------------------------------------------------

--
-- Table structure for table `trke`
--

DROP TABLE IF EXISTS `trke`;
CREATE TABLE IF NOT EXISTS `trke` (
  `id` int(12) NOT NULL AUTO_INCREMENT,
  `dogadjaj` int(12) NOT NULL,
  `vrsta_trke` int(12) unsigned NOT NULL,
  `uneto` tinyint(1) NOT NULL COMMENT 'da li su uneti rezultati trke 1-da, 0-ne',
  PRIMARY KEY (`id`),
  KEY `dogadjaj` (`dogadjaj`,`vrsta_trke`),
  KEY `vrsta_trke` (`vrsta_trke`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=18 ;

--
-- Dumping data for table `trke`
--

INSERT INTO `trke` (`id`, `dogadjaj`, `vrsta_trke`, `uneto`) VALUES
(1, 1, 1, 1),
(2, 1, 3, 1),
(3, 1, 4, 1),
(4, 2, 2, 0),
(5, 5, 4, 0),
(6, 3, 4, 0),
(7, 3, 3, 0),
(8, 4, 4, 0),
(9, 6, 2, 0),
(10, 7, 3, 0),
(11, 7, 4, 0),
(12, 8, 1, 0),
(13, 8, 2, 0),
(14, 10, 1, 0),
(15, 10, 2, 1),
(16, 9, 3, 1),
(17, 9, 4, 1);

-- --------------------------------------------------------

--
-- Table structure for table `vrste_trka`
--

DROP TABLE IF EXISTS `vrste_trka`;
CREATE TABLE IF NOT EXISTS `vrste_trka` (
  `id` int(12) unsigned NOT NULL AUTO_INCREMENT,
  `tip` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`),
  KEY `tip` (`tip`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=5 ;

--
-- Dumping data for table `vrste_trka`
--

INSERT INTO `vrste_trka` (`id`, `tip`) VALUES
(2, '10K'),
(1, '5K'),
(4, 'maraton'),
(3, 'polumaraton');

--
-- Constraints for dumped tables
--

--
-- Constraints for table `rezultati`
--
ALTER TABLE `rezultati`
  ADD CONSTRAINT `FK_trka_rez` FOREIGN KEY (`trka`) REFERENCES `trke` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_rez_trkac` FOREIGN KEY (`trkac`) REFERENCES `korisnici` (`kor_ime`) ON DELETE NO ACTION ON UPDATE CASCADE;

--
-- Constraints for table `trke`
--
ALTER TABLE `trke`
  ADD CONSTRAINT `FK_vrsta_trka` FOREIGN KEY (`vrsta_trke`) REFERENCES `vrste_trka` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_dog_trka` FOREIGN KEY (`dogadjaj`) REFERENCES `dogadjaji` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
