Why can't I update this table?

I have three tables in SQL Server 2008 R2: Country AddressandCountry_Address


Country has columns:

CountryID Country

1, Afghanistan

2, Australia


Address has columns:

AddressID Address

1, 5 Smith Way


Country_Address has columns:

CountryID AddressID

eleven

edit : so, in the example, 5 smith way is the address for Afghanistan.

I emptied the tables, then added two countries and one address, and then a link in Country_Addressbetween 1 and 1. When I try to update CountryIDfrom 1 to 2, I cannot because of FK restriction. I do not understand why this is happening, because CountryIDwhich I am trying to assign exists. So how do I update it?


edit1 . This is the error that I get when I try to upgrade in SQL Management Studio, I get InvalidOperationException- "Type model" ... "cannot be updated." in Visual Studio.

.

1 . :.Net SqlClient Data Provider. : UPDATE KEY "FK_Country_Address_Address". "...", "dbo.Address", 'AddressID'.

.

+3
2

, "" Country_Address "".

, - . .

: http://msdn.microsoft.com/en-us/library/aa933119%28SQL.80%29.aspx


: , , , , Country_Address , , CountryID. .

UPDATE Country_Address SET CountryID = 2 , . , , AddressID - , .

+5

SQL → Options-> → . . " ". " ", . , ,

0

Source: https://habr.com/ru/post/1778235/


All Articles