Mysql 5.6.12 - How to create date field with current default value

Asked

Viewed 8 times

0

I am creating a table that has a separate date and time field (yes, the two separate fields), and in these I want the default value to be the current date/time.

I tried to create the field with DEFAULT current_date(), but gives syntax error.

I tried to use also only CURRENT_DATE, also gives error.

The same occurs with the time field (CURRENT_TIME).

I know for the guy’s field timestamp, just add DEFAULT current_timestamp(), but I need the date and time to be separated.

I’m using the version 5.6.12 Mysql (yes, a bit outdated, but soon we will migrate). It has something to do with this version?

Below is the table creation script:

CREATE TABLE IF NOT EXISTS `atualizacao_sql` (
  `sqlid` BIGINT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Arquivos SQL executados durante a atualização',
  `atuid` BIGINT(10) UNSIGNED NOT NULL COMMENT 'ID da datualização',
  `sqlarqnome` VARCHAR(255) NOT NULL COMMENT 'Nome do arquivo SQL',
  `sqlord` INT(11) NOT NULL COMMENT 'Ordem de execução do arquivo',
  `sqldtexec` DATE NOT NULL DEFAULT current_date(),
  `sqlhrexec` TIME NOT NULL DEFAULT current_time(),
  `sqlsucesso` INT(1) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Executado com sucesso (0-Não/1-Sim)',
  `sqlrb` INT(1) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Executado rollback do arquivo (0-Não/1-Sim)',
  PRIMARY KEY (`sqlid`),
  INDEX `fk_atualizacao_sql_atualizacoes1_idx` (`atuid` ASC),
  CONSTRAINT `fk_atualizacao_sql_atualizacoes_atuid`
    FOREIGN KEY (`atuid`)
    REFERENCES `atualizacoes` (`atuid`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.