This is a discussion on Help! within the SQL Server forums, part of the Microsoft SQL Server category; --> Hello folks. I am somewhat new to the SQL World, but have a basic understanding of the language. I ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hello folks. I am somewhat new to the SQL World, but have a basic understanding of the language. I have a table that I am trying to update, and not having much success with it. The table has three keys and one foreign key. I cannot find the table the houses the foreign key as there is so many to look through. I will leave my error message below, along with my SQL syntax for your review. Any assistance with this issue is much appreciated! (51 row(s) affected) (51 row(s) affected) (51 row(s) affected) Msg 2627, Level 14, State 1, Line 15 Violation of PRIMARY KEY constraint 'PK_TIAHours'. Cannot insert duplicate key in object 'TIATotals'. The statement has been terminated. (0 row(s) affected) Select * into ##Temp From dbo.TIATotals where AssociateNumber = '91060139' and DeptIndex = 0 Update ##Temp set DeptIndex = 1 where AssociateNumber = '91060139' and DeptIndex = 0 Delete From TiaTotals where AssociateNumber = '91060139' and DeptIndex = 0 Insert Into TiaTotals (AssociateNumber,DeptIndex,RecordDate, ActualMinutes,CorrectedMinutes,BreakAdjust, RcdCreateUser,RcdUpdtUser,RcdCreateDateTime,RcdUpd tDateTime) Select AssociateNumber,DeptIndex,RecordDate, ActualMinutes,CorrectedMinutes,BreakAdjust, RcdCreateUser,RcdUpdtUser,RcdCreateDateTime,RcdUpd tDateTime From ##Temp Drop Table ##Temp Select * From dbo.TIATotals where AssociateNumber = '91060139' and DeptIndex = 0 |
| ||||
| This question was answered in the microsoft.public.sqlserver.server group. Please don't post the same question independently to multiple groups as this causes duplication of effort on all parties involved. -- Hope this helps. Dan Guzman SQL Server MVP http://weblogs.sqlteam.com/dang/ "papa smurf" <DSOldham@gmail.com> wrote in message news:8ef2bdbd-4868-429d-a9cd-a83eac8d6182@y21g2000hsf.googlegroups.com... > Hello folks. I am somewhat new to the SQL World, but have a basic > understanding of the language. I have a table that I am trying to > update, and not having much success with it. The table has three keys > and one foreign key. I cannot find the table the houses the foreign > key as there is so many to look through. I will leave my error > message below, along with my SQL syntax for your review. Any > assistance with this issue is much appreciated! > > (51 row(s) affected) > > (51 row(s) affected) > > (51 row(s) affected) > Msg 2627, Level 14, State 1, Line 15 > Violation of PRIMARY KEY constraint 'PK_TIAHours'. Cannot insert > duplicate key in object 'TIATotals'. > The statement has been terminated. > > (0 row(s) affected) > > Select * > into ##Temp > From dbo.TIATotals > where AssociateNumber = '91060139' > and DeptIndex = 0 > > Update ##Temp set > DeptIndex = 1 where AssociateNumber = '91060139' > and DeptIndex = 0 > > Delete From TiaTotals > where AssociateNumber = '91060139' > and DeptIndex = 0 > > Insert Into TiaTotals (AssociateNumber,DeptIndex,RecordDate, > ActualMinutes,CorrectedMinutes,BreakAdjust, > RcdCreateUser,RcdUpdtUser,RcdCreateDateTime,RcdUpd tDateTime) > Select AssociateNumber,DeptIndex,RecordDate, > ActualMinutes,CorrectedMinutes,BreakAdjust, > RcdCreateUser,RcdUpdtUser,RcdCreateDateTime,RcdUpd tDateTime From > ##Temp > > Drop Table ##Temp > > Select * > From dbo.TIATotals > where AssociateNumber = '91060139' > and DeptIndex = 0 |