What I need is to get the primary key from the Phone table and insert into the FK of the Customer table. How do I do?

1
CREATE TABLE Cliente (
    id_Cliente INTEGER PRIMARY KEY IDENTITY(1,1),
    nome_Cliente VARCHAR(50),
    fk_ID_Telefone INTEGER
)

CREATE TABLE Telefone (
    id_Telefone INTEGER PRIMARY KEY IDENTITY(1,1),
    fone_Telefone VARCHAR(11)
)
    
asked by anonymous 11.05.2018 / 16:48

1 answer

-1

Making a INSERT with SELECT :

INSERT INTO Cliente (fk_ID_Telefone) SELECT id_Telefone FROM Telefone

But if it is a UPDATE with SELECT :

UPDATE Cliente a 
JOIN Telefone b  
SET a.fk_ID_telefone=b.id_Telefone
  

INSERT Reference with SELECT

     

UPDATE with SELECT

    
11.05.2018 / 17:00