Insert Error with FK

2

I have two tables, Client and Plan, which have the 1:1 relationship. I have 3 plans registered in the bank with their respective data. But when trying to insert a Client that has a Foreing Key that is referring to Id of the chosen Plan. At the moment of inserting the data I have the following error:

  

The INSERT statement conflicted with the FOREIGN KEY constraint \ "FK_dbo.Customer.Plans_Indicator \".   The statement occurred in database \ "MyBank \", table \ "dbo.Planos \", column \ 'PlanId'. \ R \ nThe statement has been terminated.

My query

insert into Clientes values(NEWID(),'Nome do Cliente', '000.000.000-52', '001122','14966034-BC78-4B77-B817-4EC7AC483B05','logradouro','bairro','cep', 'telefone','email');

This is the value of Id of the existing Plan in the database:

14966034-BC78-4B77-B817-4EC7AC483B05

% of bank%:

    
asked by anonymous 21.12.2016 / 21:23

1 answer

0

When you create the table

CREATE TABLE Clients   (      idClient INT NOT NULL IDENTITY (1, 1) CONSTRAINT PK_Customers PRIMARY KEY (idClient),      CustomerName VARCHAR (255)   )

With IDENTITY (1, 1) you will not need NEWid () in the inserts

    
17.01.2017 / 20:39