Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Update on PK value, is it posible?

Author  Topic 

chrianth
Yak Posting Veteran

50 Posts

Posted - 2009-01-06 : 01:47:37

Hi Guys,

I want to update the field AssignmentEffectiveDate value that is part of
Constraint Type: PRIMARY KEY (clustered)
Constraint Keys: FPKey, PGuid, AssignmentEffectiveDate, MarkDelete

Is this possible?

Because when I try the query for update

update Table
set AssignmentEffectiveDate = '2009-02-29 00:00:00.000'
where FKey = 152221

I am getting error Msg 2627, Level 14, State 1, Line 1

I need this for testing in prod db, as much as posible it would be great if the suggested solution don't require dropping or changing table settings if any. Thanks.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-06 : 02:47:34
whats the purpose of updating pk? can you explain that?
Go to Top of Page

chrianth
Yak Posting Veteran

50 Posts

Posted - 2009-01-06 : 03:09:47
I want it for testing the report made by our dev here..I want to change the date so that the report would be able to return data, because there is a condition for the output of the report that select certain date of assignment to display.

Twicking this Date PK value is the only way I think that I would be able to test the report.

My initial solution for this problem would be to insert first the data into a temp table then do the twick, then after that I'll delete the records on the main table then insert back in the values I copied to a temp table together with the twicked data back again to the main table. But, still I'm looking for more better approach than this that can be done by update command only if there would be any.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-06 : 03:31:29
is there any other record having same set of values as your updated record?
Go to Top of Page

chrianth
Yak Posting Veteran

50 Posts

Posted - 2009-01-06 : 04:34:12
No. I don't think there would be a chance that if I alter the date value of 152221 to 2009-02-09 it would create duplicate entry for the set of PK's. I also verified if indeed would not cause duplicate by checking if there is a record that is existing under the date i want to have on 152221 and my query did not return any.

Table Structure:
FPKey | PGuid | AssignmentEffectiveDate | MarkDelete | Field_N....etc
152221|A1-20-H| 2009-01-09 00:00:00.000 | 0 | etc......
152221|A2-21-A| 2009-01-09 00:00:00.000 | 0 | etc......
152221|B1-22-B| 2009-01-09 00:00:00.000 | 1 | etc......
152222|B8-20-J| 2009-01-09 00:00:00.000 | 1 | etc......
152222|B9-80-1| 2009-01-09 00:00:00.000 | 1 | etc......
152222|C7-20-5| 2009-01-09 00:00:00.000 | 0 | etc......

Thanks for helping out.
Go to Top of Page

bjoerns
Posting Yak Master

154 Posts

Posted - 2009-01-06 : 12:07:33
[code]select *
into TestTable
from Table[/code]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-06 : 12:21:08
quote:
Originally posted by chrianth

No. I don't think there would be a chance that if I alter the date value of 152221 to 2009-02-09 it would create duplicate entry for the set of PK's. I also verified if indeed would not cause duplicate by checking if there is a record that is existing under the date i want to have on 152221 and my query did not return any.

Table Structure:
FPKey | PGuid | AssignmentEffectiveDate | MarkDelete | Field_N....etc
152221|A1-20-H| 2009-01-09 00:00:00.000 | 0 | etc......
152221|A2-21-A| 2009-01-09 00:00:00.000 | 0 | etc......
152221|B1-22-B| 2009-01-09 00:00:00.000 | 1 | etc......
152222|B8-20-J| 2009-01-09 00:00:00.000 | 1 | etc......
152222|B9-80-1| 2009-01-09 00:00:00.000 | 1 | etc......
152222|C7-20-5| 2009-01-09 00:00:00.000 | 0 | etc......

Thanks for helping out.


is there any trigger existing on your table?
Go to Top of Page

chrianth
Yak Posting Veteran

50 Posts

Posted - 2009-01-07 : 22:10:49
quote:
Originally posted by visakh16

quote:
Originally posted by chrianth

No. I don't think there would be a chance that if I alter the date value of 152221 to 2009-02-09 it would create duplicate entry for the set of PK's. I also verified if indeed would not cause duplicate by checking if there is a record that is existing under the date i want to have on 152221 and my query did not return any.

Table Structure:
FPKey | PGuid | AssignmentEffectiveDate | MarkDelete | Field_N....etc
152221|A1-20-H| 2009-01-09 00:00:00.000 | 0 | etc......
152221|A2-21-A| 2009-01-09 00:00:00.000 | 0 | etc......
152221|B1-22-B| 2009-01-09 00:00:00.000 | 1 | etc......
152222|B8-20-J| 2009-01-09 00:00:00.000 | 1 | etc......
152222|B9-80-1| 2009-01-09 00:00:00.000 | 1 | etc......
152222|C7-20-5| 2009-01-09 00:00:00.000 | 0 | etc......

Thanks for helping out.


is there any trigger existing on your table?



How do I check for triggers?
Go to Top of Page

chrianth
Yak Posting Veteran

50 Posts

Posted - 2009-01-07 : 22:58:13
quote:
Originally posted by chrianth

quote:
Originally posted by visakh16

quote:
Originally posted by chrianth

No. I don't think there would be a chance that if I alter the date value of 152221 to 2009-02-09 it would create duplicate entry for the set of PK's. I also verified if indeed would not cause duplicate by checking if there is a record that is existing under the date i want to have on 152221 and my query did not return any.

Table Structure:
FPKey | PGuid | AssignmentEffectiveDate | MarkDelete | Field_N....etc
152221|A1-20-H| 2009-01-09 00:00:00.000 | 0 | etc......
152221|A2-21-A| 2009-01-09 00:00:00.000 | 0 | etc......
152221|B1-22-B| 2009-01-09 00:00:00.000 | 1 | etc......
152222|B8-20-J| 2009-01-09 00:00:00.000 | 1 | etc......
152222|B9-80-1| 2009-01-09 00:00:00.000 | 1 | etc......
152222|C7-20-5| 2009-01-09 00:00:00.000 | 0 | etc......

Thanks for helping out.


is there any trigger existing on your table?



How do I check for triggers?



I found it...there was no trigger on my table.
Go to Top of Page

chrianth
Yak Posting Veteran

50 Posts

Posted - 2009-01-11 : 23:45:20
hi guys, any other suggestion? or there are really no way I can update a PK value.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-12 : 02:22:07
the error message seems like its causing pk violation. so i'm tempted to belive the update is infact creating duplicate set in table
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-01-12 : 03:27:37
[code]DECLARE @Sample TABLE
(
i INT,
j INT,
PRIMARY KEY CLUSTERED
(
i,
j
)
)

INSERT @Sample
SELECT 1, 1 UNION ALL
SELECT 2, 2

SELECT *
FROM @Sample

-- Update is OK as long as the primary key doesn't conflict
UPDATE @Sample
SET i = 3,
j = 3
WHERE i = 2

SELECT *
FROM @Sample

-- Throw same error as original poster
UPDATE @Sample
SET i = 3,
j = 3
WHERE i = 1[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -