Arthur, the ideal is that since there is a relationship between both tables only one of them (the discipline table) contains the name of the discipline.
The relationship is just this... the teacher table relates to the discipline table through the id of this discipline (immutable) and made the relationship we know which name of the discipline to which has the id linked to a teacher.
Considering this implementation you would only need to change the name of the discipline in the discipline table and would not need to worry about the rest as the relationship would make the id "translation" into the name or other columns you want from the discipline table.
Edited:
Arthur the origin of the problem lies in the way you are creating the table.
A primary call (PRIMARY KEY) can never be a value you can change, it must be an incremental and unique number for each row of your table, so I would create an entire ID field in both tables as the primary key and create an entire field in the class table which would receive the same id of the discipline you want to link, for example:
CREATE TABLE disciplina (
/* NOT NULL é dispensável considerando que uma chave primaria não pode ser nula. */
id INTEGER PRIMARY KEY,
nome VARCHAR(100) NOT NULL
);
CREATE TABLE professor (
id INTEGER PRIMARY KEY,
nome varchar(100) NOT NULL,
/*não utilizarei DELETE CASCADE pois se utilizar e um professor for removido a disciplina também será...*/
id_disciplina INTEGER NOT NULL REFERENCES disciplina(nome),
numAulas INTEGER NOT NULL,
numFaltas INTEGER
);
INSERT INTO disciplina VALUES(0 /*id da disciplina*/, 'Português');
INSERT INTO professor(id, nome, id_disciplina, numAulas)
VALUES(0 /*id do professor*/, 'Zé do Caroço', 0 /*id da disciplina relacionada*/, 0 /*numAulas*/);
/*Este SELECT retornará o nome do professor e de sua disciplina relacionada.*/
SELECT professor.nome, disciplina.nome
FROM professor
INNER JOIN disciplina ON professor.id_disciplina = disciplina.id;
Arthur, you need to consult Help and do the Soft Tour here, you need to present part of your code and also the table you are talking about. Edit your question, but first see how to address the questions here. Welcome!
– Leo
Thank you, I’ve adjusted!
– Arthur