0

I already search in here but i can't found an awnser , i have this code :

CREATE TABLE Aquario(
    ANome varchar(64) PRIMARY KEY,
    Localização varchar(8),
    Capacidade integer(15));


CREATE TABLE Habitat(
    HNome varchar(100) PRIMARY KEY,
    Iluminamento integer(10),
    Salinidade integer(2),
    pH integer(2),
    Dureza integer(3),
    Oxigenação integer(3),
    Temperatura integer(2));

CREATE TABLE contem(
    HNome varchar(64),
    ANome varchar(64),
    Percentagem_de_adequação integer(2),
    PRIMARY KEY (ANome),
    FOREIGN KEY(ANome) REFERENCES Aquario(ANome),
    FOREIGN KEY(HNome) REFERENCES Habitat(HNome));


INSERT INTO contem (Percentagem_de_adequação) VALUES (20);


INSERT INTO Aquario (ANome, Localização, Capacidade) VALUES ('Os Peixes azuis','Este',20);

INSERT INTO  Habitat (HNome, Iluminamento, Salinidade,pH,Dureza,Oxigenação,Temperatura) VALUES ('Os peixes' ,20  ,1 ,5 ,213 ,52,2);

This code don't let me do the table " contem " why ?

1
  • I really wouldn't use accented characters in table and column names. Really is asking for hassle!
    – Philᵀᴹ
    Commented Nov 3, 2016 at 16:08

1 Answer 1

1

Firstly, your datatypes and precision should always be identical on your FK references.

In Habitat you have HNome as a VARCHAR(100). In Cotem, you have HNome as a VARCHAR(64). These need to be the same.

It would help if you would post the error message you are getting, but I suspect the error is you are trying to insert a NULL value into ANome in Cotem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.