CREATE TABLE `statistics_activities_subjects` (
  `serial_sas` INT(11) NOT NULL,
  `serial_sbc` INT(11) NULL DEFAULT NULL,
  `serial_osb` INT(11) NULL DEFAULT NULL,
  `serial_att` INT(11) NOT NULL,
  `num_act_no_graded` INT NULL DEFAULT 0,
  `num_act_partially_graded` INT NULL DEFAULT 0,
  `num_act_totally` INT NULL DEFAULT 0,
  `status_sas` ENUM('ACTIVE', 'INACTIVE') NOT NULL DEFAULT 'ACTIVE',
  PRIMARY KEY (`serial_sas`));
  
  ALTER TABLE `statistics_activities_subjects` 
CHANGE COLUMN `num_act_totally` `num_act_totally_graded` INT(11) NULL DEFAULT '0' ;

 
 ALTER TABLE `statistics_activities_subjects` 
CHANGE COLUMN `serial_sas` `serial_sas` INT(11) NOT NULL AUTO_INCREMENT ;

  ALTER TABLE `statistics_activities_subjects` 
ADD COLUMN `serial_sbp` INT(11) NOT NULL AFTER `serial_osb`,
ADD INDEX `fk_subperiod_sas_idx` (`serial_sbp` ASC),
ADD INDEX `fk_optional_subject_sas_idx` (`serial_osb` ASC),
ADD INDEX `fk_subjectcourse_sas_idx` (`serial_sbc` ASC),
ADD INDEX `fk_activitytype_sas_idx` (`serial_att` ASC);
ALTER TABLE `statistics_activities_subjects` 
ADD CONSTRAINT `fk_subperiod_sas`
  FOREIGN KEY (`serial_sbp`)
  REFERENCES `subperiod` (`serial_sbp`)
  ON DELETE NO ACTION
  ON UPDATE NO ACTION,
ADD CONSTRAINT `fk_optional_subject_sas`
  FOREIGN KEY (`serial_osb`)
  REFERENCES `optional_subject` (`serial_osb`)
  ON DELETE NO ACTION
  ON UPDATE NO ACTION,
ADD CONSTRAINT `fk_subjectcourse_sas`
  FOREIGN KEY (`serial_sbc`)
  REFERENCES `subject_course` (`serial_sbc`)
  ON DELETE NO ACTION
  ON UPDATE NO ACTION,
ADD CONSTRAINT `fk_activitytype_sas`
  FOREIGN KEY (`serial_att`)
  REFERENCES `activity_type` (`serial_att`)
  ON DELETE NO ACTION
  ON UPDATE NO ACTION;
