DROP TABLE IF EXISTS `question`;
CREATE TABLE `question` (
  `PK_question_id` int NOT NULL,
  `FK_users_id` int NOT NULL DEFAULT '0',
  `question` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `date_question` datetime NOT NULL,
  `valid_question` int NOT NULL DEFAULT '0',
  `online_question` int NOT NULL DEFAULT '0',
  `actif_question` int NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `vote`;
CREATE TABLE `vote` (
  `PK_vote_id` int NOT NULL,
  `libelle_vote` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `online_vote` int NOT NULL DEFAULT '0',
  `actif_vote` int NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `vote_item`;
CREATE TABLE `vote_item` (
  `PK_vote_item_id` int NOT NULL,
  `FK_vote_id` int NOT NULL,
  `libelle_vote_item` varchar(220) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `ordre_vote_item` int NOT NULL DEFAULT '0',
  `actif_vote_item` int NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `vote_item_count`;
CREATE TABLE `vote_item_count` (
  `PK_vote_item_count_id` int NOT NULL,
  `FK_vote_item_id` int NOT NULL,
  `FK_users_id` int NOT NULL DEFAULT '0',
  `date_vote_item` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


ALTER TABLE `question`
  ADD PRIMARY KEY (`PK_question_id`),
  ADD KEY `FK_users_id` (`FK_users_id`),
  ADD KEY `date_question` (`date_question`),
  ADD KEY `valid_question` (`valid_question`),
  ADD KEY `online_question` (`online_question`),
  ADD KEY `actif_question` (`actif_question`);

ALTER TABLE `vote`
  ADD PRIMARY KEY (`PK_vote_id`),
  ADD KEY `libelle_vote` (`libelle_vote`(333)),
  ADD KEY `actif_vote` (`actif_vote`),
  ADD KEY `online_vote` (`online_vote`);

ALTER TABLE `vote_item`
  ADD PRIMARY KEY (`PK_vote_item_id`),
  ADD KEY `FK_vote_id` (`FK_vote_id`),
  ADD KEY `libelle_vote_item` (`libelle_vote_item`),
  ADD KEY `actif_vote_item` (`actif_vote_item`),
  ADD KEY `ordre_vote_item` (`ordre_vote_item`);

ALTER TABLE `vote_item_count`
  ADD PRIMARY KEY (`PK_vote_item_count_id`),
  ADD KEY `FK_vote_item_id` (`FK_vote_item_id`),
  ADD KEY `FK_users_id` (`FK_users_id`),
  ADD KEY `date_vote_item` (`date_vote_item`);


ALTER TABLE `question`
  MODIFY `PK_question_id` int NOT NULL AUTO_INCREMENT;

ALTER TABLE `vote`
  MODIFY `PK_vote_id` int NOT NULL AUTO_INCREMENT;

ALTER TABLE `vote_item`
  MODIFY `PK_vote_item_id` int NOT NULL AUTO_INCREMENT;

ALTER TABLE `vote_item_count`
  MODIFY `PK_vote_item_count_id` int NOT NULL AUTO_INCREMENT;
COMMIT;
