2
I have two tables and when I try to use a key of the 1st table in the 2nd the value appears NULL and should appear the values that appear in Aquario
CREATE TABLE Aquario(
ANome varchar(64) PRIMARY KEY,
Localizacao 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),
Oxigenacao integer(3),
Temperatura integer(2),
Percentagem_de_adequacao integer(2),
ANome varchar(64),
FOREIGN KEY (ANome) REFERENCES Aquario(ANome));
INSERT INTO Aquario(ANome,Localizacao,Capacidade) VALUES('Os Peixes azuis','Este',20);
INSERT INTO Habitat( HNome,Iluminamento , Salinidade,pH , Dureza, Oxigenacao, Temperatura,Percentagem_de_adequacao) VALUES ('Os peixes',20,1,5,213,52,2,59);
The foreign key is for you to link a record from one table to another, that is, it will not automatically fetch information for you in another table.
– Sorack
So how do I get the values from the 1st table to the 2nd with FOREIGN KEY ?
– Força Chape
I put in the answer below
– Sorack
Thank you very much , helped a lot
– Força Chape