--------------------------------------------------------------------------- -- TO CREATE A SURVEY --------------------------------------------------------------------------- --Create a new survey: INSERT INTO `surveys` (`title` ) VALUES ('How old are you ?'); -- Get the ID of the survey just created: surveyID = Select LAST_INSERT_ID(); -- Add the option 'Rock' which is number selectionNumber, to this survey: INSERT INTO `survey_options` (`survey_id`, `selection_number`, `text`) VALUES("+surveyID+", "+selectionNumber+", 'Rock'); -- To modify an option: UPDATE `survey_options` SET `text` = 'Pop/Rock' WHERE `survey__id` ="+surveyID+" AND `selection_number`=1; -- Add the second option of this survey: INSERT INTO `survey_options` (`survey_id`, `selection_number`, `text`) VALUES("+surveyID+", 2, 'Jazz'); ... etc ----------------------------------------------- -- DEFINE THE DEFAULT SURVEY ----------------------------------------------- -- Determine if there is already a default survey: (if the number returned is greater than 0, there is already a defalu survey) SELECT count(*) FROM `activations` WHERE `activations`.`type` = 'survey' AND `activations`.`desactivation_date` = NULL AND `activations`.`activation_date` = NULL; -- Insert a new default survey: INSERT INTO `activations` (`type`, `type_id`) VALUES ('survey', 1); -- Modify the default survey (change ID 1 to 2): UPDATE `activations` SET `type_id` =2 WHERE `activation_date` = NULL AND `desactivation_date` = NULL LIMIT 1;