Создание веб-приложения, сочетающего в себе проектирование и создание баз данных, работу со сторонними форматами данных, программирование в NET и веб-разработку, страница 29

  KEY `foreign_te` (`team`),

  CONSTRAINT `auth_user_ibfk_1` FOREIGN KEY (`role`) REFERENCES `roles` (`id`),

  CONSTRAINT `auth_user_ibfk_2` FOREIGN KEY (`team`) REFERENCES `teams` (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8$$

delimiter $$

CREATE TABLE `roles` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `name` varchar(25) NOT NULL,

  PRIMARY KEY (`id`),

  UNIQUE KEY `unique_role` (`name`)

) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8$$

delimiter $$

CREATE TABLE `teams` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `abb` varchar(10) NOT NULL,

  `name` varchar(50) NOT NULL,

  `city` varchar(50) NOT NULL,

  `division` int(11) NOT NULL,

  `logo` varchar(255) DEFAULT '',

  PRIMARY KEY (`id`),

  KEY `foreign_division` (`division`),

  CONSTRAINT `teams_ibfk_1` FOREIGN KEY (`division`) REFERENCES `divisions` (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8$$

delimiter $$

CREATE TABLE `divisions` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `name` varchar(50) NOT NULL,

  `conference` int(11) NOT NULL,

  PRIMARY KEY (`id`),

  KEY `divisions_ibfk_1` (`conference`),

  CONSTRAINT `divisions_ibfk_1` FOREIGN KEY (`conference`) REFERENCES `conferences` (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8$$

delimiter $$

CREATE TABLE `conferences` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `name` varchar(50) NOT NULL,

  `league` int(11) NOT NULL,

  PRIMARY KEY (`id`),

  KEY `league` (`league`),

  CONSTRAINT `conferences_ibfk_1` FOREIGN KEY (`league`) REFERENCES `tournaments` (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8$$

delimiter $$

CREATE TABLE `tournaments` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `name` varchar(250) NOT NULL,

  `w` int(11) NOT NULL DEFAULT '3',

  `w_ot` int(11) NOT NULL DEFAULT '2',

  `w_so` int(11) NOT NULL DEFAULT '2',

  `l_so` int(11) NOT NULL DEFAULT '1',

  `l_ot` int(11) NOT NULL DEFAULT '1',

  `l` int(11) NOT NULL DEFAULT '0',

  `capspace` float DEFAULT '0',

  PRIMARY KEY (`id`),

  UNIQUE KEY `unique_name` (`name`)

) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8$$

delimiter $$

CREATE TABLE `players` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `name` varchar(50) NOT NULL,

  `position` varchar(5) NOT NULL,

  `shots` varchar(6) NOT NULL,

  `birthdate` date NOT NULL,

  `photo` varchar(255) DEFAULT NULL,

  `team` int(11) DEFAULT NULL,

  `caphit` float DEFAULT '0',

  PRIMARY KEY (`id`),

  KEY `position` (`position`),

  KEY `shots` (`shots`),

  KEY `foreign_team` (`team`),

  CONSTRAINT `players_ibfk_1` FOREIGN KEY (`position`) REFERENCES `player_position` (`pos`),

  CONSTRAINT `players_ibfk_2` FOREIGN KEY (`shots`) REFERENCES `hand_shots` (`shots`),

  CONSTRAINT `players_ibfk_3` FOREIGN KEY (`team`) REFERENCES `teams` (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8$$

delimiter $$

CREATE TABLE `player_position` (

  `pos` varchar(5) NOT NULL,

  PRIMARY KEY (`pos`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8$$

delimiter $$

CREATE TABLE `hand_shots` (

  `shots` varchar(6) NOT NULL,

  PRIMARY KEY (`shots`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8$$

delimiter $$

CREATE TABLE `seasons` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `season` varchar(255) NOT NULL,

  `league` int(11) NOT NULL,

  `open` tinyint(1) NOT NULL DEFAULT '1',

  PRIMARY KEY (`id`),

  UNIQUE KEY `season_UNIQUE` (`season`),

  KEY `league` (`league`),

  CONSTRAINT `seasons_ibfk_1` FOREIGN KEY (`league`) REFERENCES `tournaments` (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8$$

delimiter $$

CREATE TABLE `couching` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `user` int(11) NOT NULL,

  `season` int(11) NOT NULL,

  `team` int(11) NOT NULL,

  `date_appointment` datetime NOT NULL,

  `date_discharge` datetime DEFAULT NULL,

  PRIMARY KEY (`id`),

  KEY `user` (`user`),

  KEY `team` (`team`),

  KEY `foreign_season` (`season`),