I’m having a stupid question, but it’s been a while and I don’t know how to solve it. (Mysql)

Asked

Viewed 118 times

1

I was trying to create a table in mysql, simple, but it was giving an error. I decided to download an ide (Dbeaver), it kept giving error, so I downloaded Mysql Workbench and it does not generate the table. See the error:

CREATE TABLE `wmp_fut`.`contratos` (
  `id_campeonato` INT NOT NULL AUTO_INCREMENT,
  `nome_campeonato` VARCHAR(100) NOT NULL,
  `negociacoes` ENUM('Aberto', 'Fechado') NOT NULL,
  `validade` DATE NOT NULL DEFAULT 2020-01-01,
  PRIMARY KEY (`id_campeonato`),
  UNIQUE INDEX `nome_campeonato_UNIQUE` (`nome_campeonato` ASC));


Operation failed: There was an error while applying the SQL script to the database.
Executing:
CREATE TABLE `wmp_fut`.`contratos` (
  `id_campeonato` INT NOT NULL AUTO_INCREMENT,
  `nome_campeonato` VARCHAR(100) NOT NULL,
  `negociacoes` ENUM('Aberto', 'Fechado') NOT NULL,
  `validade` DATE NOT NULL DEFAULT 2020-01-01,
  PRIMARY KEY (`id_campeonato`),
  UNIQUE INDEX `nome_campeonato_UNIQUE` (`nome_campeonato` ASC));

ERROR 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-01-01,
  PRIMARY KEY (`id_campeonato`),
  UNIQUE INDEX `nome_campeonato_UNIQUE`' at line 5
SQL Statement:
CREATE TABLE `wmp_fut`.`contratos` (
  `id_campeonato` INT NOT NULL AUTO_INCREMENT,
  `nome_campeonato` VARCHAR(100) NOT NULL,
  `negociacoes` ENUM('Aberto', 'Fechado') NOT NULL,
  `validade` DATE NOT NULL DEFAULT 2020-01-01,
  PRIMARY KEY (`id_campeonato`),
  UNIQUE INDEX `nome_campeonato_UNIQUE` (`nome_campeonato` ASC))

. Can anyone solve it? Mysql and Bds in general are not my language, excuse the stupid question.

1 answer

1


ERROR 1064: You have an error in your SQL syntax; check the manual that Corresponds to your Mysql server version for the right syntax to use near '-01-01

The message informs that the problem is in the syntax and the location is next where it is written "-01-01". In your example this location is the field validade. In the case was passed a kind of data that is not expected by the field.

Use quotes to set values of type DATE. That should solve your problem:

CREATE TABLE `wmp_fut`.`contratos` (
  `id_campeonato` INT NOT NULL AUTO_INCREMENT,
  `nome_campeonato` VARCHAR(100) NOT NULL,
  `negociacoes` ENUM('Aberto', 'Fechado') NOT NULL,
  `validade` DATE NOT NULL DEFAULT '2020-01-01',
  PRIMARY KEY (`id_campeonato`),
  UNIQUE INDEX `nome_campeonato_UNIQUE` (`nome_campeonato` ASC)
);
  • Buddy, thank you!

Browser other questions tagged

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