The order for you to enter the data in the Table would be first by the tables that will be foreign...
For example, we have the table TIMES
and the table JOGADORES
:
CREATE TABLE TIMES
(
COD_TIME NUMBER(3) NOT NULL,
NOME VARCHAR2(100) NOT NULL,
CONSTRAINT PK_TIMES PRIMARY KEY (COD_TIME)
);
CREATE TABLE JOGADORES
(
COD_JOGADOR NUMBER(3) NOT NULL,
NOME VARCHAR2(100) NOT NULL,
COD_TIME NUMBER(3) NOT NULL,
CONSTRAINT PK_JOGADORES PRIMARY KEY (COD_JOGADOR),
CONSTRAINT FK_TIMES_JOGADORES FOREIGN KEY (COD_TIME) REFERENCES TIMES
);
In our example, each player has a team: If we start to popular the tables by the table JOGADORES
, there will be no team, because we have not added any record in the table TIMES
.
In the image, I tried to add a JOGADOR
with the TIME
of CODIGO = 1
, but gave me a mistake, which happens because there is no CODIGO = 1
on the table TIMES
, I mean, it’s like I’m saying that a player is part of a team that doesn’t exist yet.
From the moment I created the TIME
, giving a INSERT
on the table TIMES
with a record of COD_TIME = 1
, then we can add the JOGADOR
.
That is, answering your question, you need to start inserting record by tables that do not have a FOREIGN KEY
linked to them, unless the foreign table already has records.
In your case, in the table AERONAVE
, it would not be possible to add a AERONAVE
without first adding registration in STATUS
and in TIPO_AERONAVE
(Unless those columns accept NULL).
Do you have any table structure to put next to the question?
– Woss
Worst of all, I had this doubt, so I was putting the Serts and testing which one worked
– punkoco
So you have an example?
– Tiedt Tech
I have a bank here, but it’s very large, as you want me to send ?
– punkoco
Take a photo or print of the relational model.
– Antonio_Sistema_de_Informacao
Assemble a basic example here http://sqlfiddle.com/
– Tiedt Tech
edited the post with an example
– punkoco