1
CREATE TABLE Produto (
  Codigo_Produto INTEGER,
  Descricao_Produto VARCHAR(50),
  Preco_Produto FLOAT,
  PRIMARY KEY (Codigo_Produto)
);
CREATE TABLE Nota_fiscal (
  Numero_NF INTEGER,
  Data_NF DATE,
  Valor_NF FLOAT,
  PRIMARY KEY (Numero_NF)
);
CREATE TABLE Itens (
    Produto_Codigo_Produto INTEGER,
    Nota_fiscal_Numero_NF INTEGER,
    Num_Item INTEGER,
    Qtde_Item INTEGER,
        PRIMARY KEY(Produto_Codigo_Produto, Nota_fiscal_Numero_NF),
    FOREIGN KEY (Produto_Codigo_Produto) REFERENCES Produto(Codigo_Produto),
    FOREIGN KEY (Nota_fiscal_Numero_NF) REFERENCES Nota_fiscal(Numero_NF)
);
I have a problem, I have an exercise q have to create these 3 tables, but then I have to perform the following action: "Make the primary key of the Items table no longer composed by code of the product. more number of the invoice and become Num_item" However, when I try to run the following code:
ALTER TABLE Itens DROP PRIMARY KEY;
ALTER TABLE Itens
ADD PRIMARY KEY (Num_Item);
mysql returns this error: "Error Code: 1025. Error on Rename of './sales/#sql-1_11' to './sales/items' (Rrno: 150 - Foreign key Constraint is incorrectly Formed) "
Does anyone know what it can be?