1

I have a country table which have a column Countryid I accidently deleted the CountryId Which Had value=1 and now in state table there is a value of column countryId=1 which is used to fetch the records (states) according to country id. I had inserted the country again but it has different id so how can I update the value again in country table of CountryId which primary key from 2 to

Gaurav_0093
  • 1,040
  • 6
  • 28
  • 56

1 Answers1

5

The direct answer to your question is to use set identity_insert off. The best place to start is with the documentation.

More important, there is a very simple way to avoid these problems in the future: use explicitly declared foreign key relationships. If you had a foreign key constraint:

alter table state
    add constraint fk_state_country foreign key (countryId) references country(countryId);

Then the delete would not have been allowed.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786