How to create a table in Oracle using foreign key

0

The situation is that I have a table called OS and I want to create a link from this OS table to the CLIENT, using the CPF column as FK. Where am I going wrong?

I am editing the direct database of Netbeans data. The client table has already been created and has CPF as PK.

CREATE TABLE OS (
NUMEROOS NUMBER(9) NOT NULL PRIMARY KEY,
DATAABERTURA VARCHAR2(40) NOT NULL,
HORARIOABERTURA VARCHAR2(40) NOT NULL,
STATUS VARCHAR2(40) NOT NULL,
CPF VARCHAR2(14) FOREIGN KEY REFERENCES CLIENTE(CPF),
DISPOSITIVO VARCHAR2(40) NOT NULL,
MARCA VARCHAR2(40) NOT NULL,
MODELO VARCHAR2(40) NOT NULL,
NUMEROSERIE VARCHAR2(40),
IMEI VARCHAR2(40),
DESCRICAOPROBLEMA VARCHAR2(400) NOT NULL,
OBSERVACOES VARCHAR2(40)
)
    
asked by anonymous 25.10.2018 / 03:08

1 answer

0

Place a constraint referencing a foreign key, like this:

CREATE TABLE TB_FONTE_FINANCIAMENTO
(
  FF_ID NUMBER(10) PRIMARY KEY NOT NULL,
  FF_DESCRICAO VARCHAR2(100) NOT NULL,
  FF_SITUACAO VARCHAR2(10) DEFAULT 'Ativo' NOT NULL
);
CREATE TABLE TB_PROJETO
(
  PJ_ID NUMBER(10) PRIMARY KEY NOT NULL,
  PJ_DESCRICAO VARCHAR2(100) NOT NULL,
  PJ_SITUACAO VARCHAR2(10) DEFAULT 'Ativo' NOT NULL,
  FF_ID NUMBER(10) NOT NULL,
  CONSTRAINT FK_FONTE_FINANCIAMENTO FOREIGN KEY (FF_ID) REFERENCES TB_FONTE_FINANCIAMENTO (FF_ID)
);
    
26.10.2018 / 14:15