SQL command in MYSQL

Asked

Viewed 451 times

-2

I’m creating a DBA and I need to make one CHECK on an index of my table produto, but I’m using Mysql and I’m having a problem with the syntax.

Follow the example:

CREATE TABLE produto(
Cod_produto int primary key not null,
nome_produto varchar(50) NOT NULL,
descricao text, 
cod_tipoProduto int  not null,
valor_Compra decimal (12,3) not null,
valor_Venda decimal (12,3) not null,
CONSTRAINT valorDeVenda CHECK  valor_Venda IN (valor_Venda>= 0),
CONSTRAINT valorDeCompra CHECK valor_Compra IN (valor_Compra>=0)

);

Error

inserir a descrição da imagem aqui

  • 1

    What problem are you having? Which error is being returned? Be more specific.

  • I updated the error, with an image to be more specific

1 answer

2

The error is where you mount the CHECK, doesn’t need the valor_Venda IN:

CREATE TABLE produto(
  Cod_produto int primary key not null,
  nome_produto varchar(50) NOT NULL,
  descricao text, 
  cod_tipoProduto int  not null,
  valor_Compra decimal (12,3) not null,
  valor_Venda decimal (12,3) not null,
  CONSTRAINT CHK_valorDeVenda CHECK (valor_Venda>= 0),
  CONSTRAINT CHK_valorDeCompra CHECK (valor_Compra>=0)
);
  • So I’ve tried it this way and it’s giving the same Mistakes, the Image that’s in the question.

  • tried to create direct without adding a name? type valor_Venda decimal (12,3) not null, CHECK (valor_Venda >= 0)

  • Yes, I took a look at the documentation and W3school with the examples . I have already taken the following Test. valueVenda decimal (12,3) not null, CHECK (value_Venda >= 0) , value_Venda decimal CHECK(value_sale>=0) and the creation of Straint that still continues with the same error

Browser other questions tagged

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