Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more: , +
table: Country
{
Country varchar(50)
}


sample Data:
Country
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

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 :)

Hope this helps

Regards, Pasan.
 
Share this answer
 
v2
Comments
Dave Paras 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900