﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2005 / SQL Server 2005 General Discussion  / working with primary key column / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Tue, 18 Jun 2013 17:45:18 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: working with primary key column</title><link>http://www.sqlservercentral.com/Forums/Topic724790-149-1.aspx</link><description>Updating the Primary Key (1) to (1+1=2) would create two records with the same Primary Key (2). This will not work, and should not be attempted.A Primary Key [u]constraint[/u] requires the column to be unique; and [u]constrains[/u] the user's actions to keep this rule.Perhaps you are trying to update the Foreign Keys (the related records)?Table 1======ColourID | Colour1 | red2 | blue3 | green4 | yellowTable 2=====ItemID | Item | ColourID 1 |Red Car |12 |Red Brick |13 |Red Pencil|14 |Blue things|2If ColourID in table 1 was updated from 1 to 2, the PKEY 2 would mean both red and blue, and the related items in table 2 would appear as both red and blue (1,red car,code for blue &amp; code for red)etc.</description><pubDate>Mon, 01 Jun 2009 07:01:33 GMT</pubDate><dc:creator>dhulme</dc:creator></item><item><title>RE: working with primary key column</title><link>http://www.sqlservercentral.com/Forums/Topic724790-149-1.aspx</link><description>Hi,Please run below steps on your test database.create table test (col1 int primary key, col2 varchar(10) )insert into test values(1,'col1')insert into test values(2,'col2')insert into test values(3,'col3')insert into test values(4,'col4')select * from testupdate test set col1=col1+1select * from testYou will see it will update the column without any problem...:)Now the reason:We know SQL server works in Auto Commit mode means what ever query we write on Query Window automatically got comitted. Now this will only happen by the time it will complete its execution. So Once execution will be done all rows will be succesfully updated by new values.Please let me know if you are facing any problem. Please share your script as well if its there.RegardsGurpreet Sethi</description><pubDate>Thu, 28 May 2009 01:08:11 GMT</pubDate><dc:creator>GURSETHI</dc:creator></item><item><title>working with primary key column</title><link>http://www.sqlservercentral.com/Forums/Topic724790-149-1.aspx</link><description>if a table is having 2 columns col1 and col2. if col1 is primary key.col1 col21	"aa"2	"bb"3	"cc"4	"dd"if i want to run some update query on this table as update table tab-nameset col1 = col1 + 1it will cause primary key constraint violation error.So is it ok, we can do the same work by disabling the primary key constraint ??</description><pubDate>Wed, 27 May 2009 22:43:33 GMT</pubDate><dc:creator>harish_ravi</dc:creator></item></channel></rss>