3
CREATE TABLE PESSOA
(
ID INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
CPF VARCHAR(15) NOT NULL,
RG VARCHAR(10) NOT NULL,
NOME VARCHAR(128) NOT NULL,
DATA_NASCIMENTO DATE,
PRIMARY KEY (ID)
)
CREATE TABLE CADASTRO
(
ID INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
RA INTEGER UNSIGNED NOT NULL,
NOME VARCHAR(128),
NOTA_TEORICA NUMERIC(10,2),
NOTA_LAB NUMERIC(10,2),
MEDIA NUMERIC(10,5),
FK_CPF INTEGER UNSIGNED NOT NULL,
PRIMARY KEY(ID)
)
I need the CPF field of the PESSOA table to be a foreign key in FK_CPF of the CADASTRO table
Out of curiosity, why don’t you use the ID as FK? Are you sure you did the modeling correctly? If the CPF is not PK or UK, it will not be possible to register two people with the same CPF?
– Jéf Bueno
In this specific case I need the CPF, but it could also be UK, not even thought about it ... how would sql then so that it is UK in the PERSON table and that is referenced in FK_CPF ?
– Danilo Tiago Thai Santos
CPF is varchar or integer?
– Jéf Bueno
Cpf is a varchar
– Danilo Tiago Thai Santos