Click here to Skip to main content
11,930,069 members (50,065 online)
Rate this:
Please Sign up or sign in to vote.
table: Country
Country varchar(50)

sample Data:
1. India
2. USA

What I want is Update Country field. But its primary key. So i got following error.
The property 'Country' is part of the object's key information and cannot be modified.

So please help me how to achieve this task.

Thanks in advance...
Posted 9-Mar-11 0:53am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hi there...

You can update any field in a table. The reason, why you cannot edit the primary key value here, is that it (the primary key) has been referenced by another table as a foreign key. You will have to drop/change any referencing rows in other tables in order to update this "Country" column.

On a side note, in real world the best practice is to create a table called "Country" with 2 columns. One integer column which is the primary key called "ID" and the other column a varchar(50) named "description". You can make the ID column an auto-incremental field to reduce the hassle and make the "Description" column a unique index. Update the other tables to refer to the "ID" column as a foreign key. The key advantage in this approach is, you can change the description which is the name of the country to anything else without updating the ID, which I think what you want to achieve Smile | :)

Hope this helps

Regards, Pasan.
Dave Parth 9-Mar-11 6:35am
Hi Pasan,
But its requirement not to create additional column of Id.
Other reason is that database huge containing more than hundreads of tables, so this change take much time and its not affordable.

So in this context, if you will provide me any solution then it will be really helpful to me.

By the way Thanks for reply.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151126.1 | Last Updated 10 Nov 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100