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.
Author |
Topic |
igaraj7
Starting Member
3 Posts |
Posted - 2009-01-16 : 12:27:42
|
Hi,I have been trying to update some columns in a table that has a unique id field(Primary Key). The columns i want to update do not have a constraint on them. When i try to update these colums i get an error . i am not trying to update data in Primary Key column¨Server: Msg 2627, Level 14, State 2, Line 1Violation of UNIQUE KEY constraint 'uc_prices1'. Cannot insert duplicate key in object 'prices'.The statement has been terminated.¨why is this happening i am not changing the data in the primary key column. what am i doing wrong. Help please |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-16 : 12:35:16
|
seems like the column you're trying to update is a part of the constraint uc_prices1. in such case, inserting a value that cause duplicate combination value will throw error. first look at definition of constraint to understand what all columns are involved. |
|
|
igaraj7
Starting Member
3 Posts |
Posted - 2009-01-16 : 12:45:01
|
Hi visakh16Thanks for advise. I looked up constraintALTER TABLE [dbo].[prices] ADD CONSTRAINT [uc_prices1] UNIQUE CLUSTERED ( [product], [list_no], [effective_from] ) WITH FILLFACTOR = 90 ON [PRIMARY] what does this mean. i am trying to change effective_from field. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-16 : 12:49:10
|
this means the combination of [product],[list_no],[effective_from] values should be unique. so if you're updating [effective_from] value to one such that the combination value of [product],[list_no],[effective_from] already exists then it will throw error. |
|
|
igaraj7
Starting Member
3 Posts |
Posted - 2009-01-16 : 12:58:08
|
Thanks visakh16,it works. Thanks a million |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-16 : 13:02:16
|
welcome |
|
|
|
|
|
|
|