CREATE DATABASE IF NOT EXISTS rodokmen;
USE rodokmen;

CREATE TABLE `chovatelia` (
  `id_chovatel` int(11) NOT NULL auto_increment,
  `nazov` varchar(50) collate utf8_general_ci NOT NULL,
  `adresa` varchar(50) collate utf8_general_ci NOT NULL,
  `adresa1` varchar(50) collate utf8_general_ci NOT NULL,
  `popis` text collate utf8_general_ci NOT NULL,
  PRIMARY KEY  (`id_chovatel`)
) ENGINE=MyISAM AUTO_INCREMENT=14 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

CREATE TABLE `log` (
  `id_uzivatel` int(11) NOT NULL,
  `akcia` text collate utf8_general_ci,
  `cas` varchar(20) collate utf8_general_ci default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

CREATE TABLE `rodokmen` (
  `id_jedinec` int(11) NOT NULL auto_increment,
  `id_chovatel` int(11) NOT NULL default '-1',
  `rasa` varchar(20) collate utf8_general_ci default NULL,
  `cislo` varchar(20) collate utf8_general_ci default NULL,
  `meno` varchar(20) collate utf8_general_ci default NULL,
  `farba` varchar(20) collate utf8_general_ci default NULL,
  `pohlavie` tinyint(1) NOT NULL default '-1',
  `popis` text collate utf8_general_ci,
  `otec` varchar(20) collate utf8_general_ci default NULL,
  `matka` varchar(20) collate utf8_general_ci default NULL,
  `zivy` tinyint(1) NOT NULL default '0',
  `foto` longblob,
  PRIMARY KEY  (`id_jedinec`)
) ENGINE=MyISAM AUTO_INCREMENT=187 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

CREATE TABLE `zostavy` (
  `id_uzivatel` int(11) NOT NULL,
  `rasa` tinyint(1) NOT NULL default '0',
  `pchovatel` tinyint(1) NOT NULL default '0',
  `pjedincov` tinyint(1) NOT NULL default '0',
  `c_cislo` varchar(30) collate utf8_general_ci NOT NULL default 'clBlack',
  `c_meno` varchar(30) collate utf8_general_ci NOT NULL default 'clBlue',
  `c_rasa` varchar(30) collate utf8_general_ci NOT NULL default 'clPurple',
  `c_farba` varchar(30) collate utf8_general_ci NOT NULL default 'clBlue',
  `c_popis` varchar(30) collate utf8_general_ci NOT NULL default 'clBlack',
  PRIMARY KEY  (`id_uzivatel`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

INSERT INTO `zostavy` (`id_uzivatel`,`rasa`,`pchovatel`,`pjedincov`,`c_cislo`,`c_meno`,`c_rasa`,`c_farba`,`c_popis`) VALUES 
 (1,3,1,1,'clBlack','clScrollBar','clMenuHighlight','clGreen','clTeal');

DROP VIEW IF EXISTS `view_rodokmen`;
CREATE VIEW `view_rodokmen` AS select `rodokmen`.`id_jedinec` AS `id_jedinec`,`rodokmen`.`id_chovatel` AS `id_chovatel`,`rodokmen`.`rasa` AS `rasa`,`rodokmen`.`cislo` AS `cislo`,`rodokmen`.`meno` AS `meno`,`rodokmen`.`farba` AS `farba`,`rodokmen`.`popis` AS `popis`,`rodokmen`.`otec` AS `otec`,`rodokmen`.`matka` AS `matka`,`rodokmen`.`zivy` AS `zivy`,`rodokmen`.`web` AS `web`,`rodokmen`.`akt` AS `akt`,`chovatelia`.`nazov` AS `chovatel` from (`rodokmen` join `chovatelia`) where (`rodokmen`.`id_chovatel` = `chovatelia`.`id_chovatel`);

DROP VIEW IF EXISTS `view_rodokmen_foto`;
CREATE VIEW `view_rodokmen_foto` AS select `rodokmen`.`id_jedinec` AS `id_jedinec`,`rodokmen`.`id_chovatel` AS `id_chovatel`,`rodokmen`.`rasa` AS `rasa`,`rodokmen`.`cislo` AS `cislo`,`rodokmen`.`meno` AS `meno`,`rodokmen`.`farba` AS `farba`,`rodokmen`.`popis` AS `popis`,`rodokmen`.`otec` AS `otec`,`rodokmen`.`matka` AS `matka`,`rodokmen`.`zivy` AS `zivy`,`rodokmen`.`web` AS `web`,`rodokmen`.`akt` AS `akt`,`rodokmen`.`foto` AS `foto`,`chovatelia`.`nazov` AS `chovatel` from (`rodokmen` join `chovatelia`) where (`rodokmen`.`id_chovatel` = `chovatelia`.`id_chovatel`)
