SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


UPDATE statement conflicted with the FOREIGN KEY constraint


UPDATE statement conflicted with the FOREIGN KEY constraint

Author
Message
daniel vella-471037
daniel vella-471037
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 8
I am running the following procedure:



ALTER PROCEDURE [dbo].[spA_FSH_InsertVslLic5]

@ID INT=NULL,

@CrewMaxNumber NUMERIC(2,0)=NULL,

@CrewMinNumber NUMERIC(2,0)=NULL,

@FullTimeFishermenNumber NUMERIC(2,0)=NULL,

@CrewRemarks VARCHAR(30)=NULL,

@FirstPortID INT=NULL,

@OperativePeriodOne VARCHAR(30)=NULL,

@SecondPortID INT=NULL,

@OperativePeriodTwo VARCHAR(30)=NULL,

@ThirdPortID INT=NULL,

@OperativePeriodThree VARCHAR(30)=NULL,

@ForthPortID INT=NULL,

@OperativePeriodFour VARCHAR(30)=NULL,

@FifthPortID INT=NULL,

@OperativePeriodFive VARCHAR(30)=NULL

AS

BEGIN

BEGIN TRY

UPDATE tb_vessellic_vsl_fsh

SET

vsl_CrewMaxNumber = @CrewMaxNumber,

vsl_CrewMinNumber = @CrewMinNumber,

vsl_FullTimeFishermenNumber = @FullTimeFishermenNumber,

vsl_CrewRemarks = @CrewRemarks,

vsl_prt_FirstPortID_fk = @FirstPortID,

vsl_OperativePeriodOne = @OperativePeriodOne,

vsl_prt_SecondPortID_fk = @SecondPortID,

vsl_OperativePeriodTwo = @OperativePeriodTwo,

vsl_prt_ThirdPortID_fk = @ThirdPortID,

vsl_OperativePeriodThree = @OperativePeriodThree,

vsl_prt_FourthPortID_fk = @ForthPortID,

vsl_OperativePeriodFour = @OperativePeriodFour,

vsl_prt_FifthPortID_fk = @FifthPortID,

vsl_OperativePeriodFive = @OperativePeriodFive

WHERE vsl_ID_pk = @ID

END TRY

BEGIN CATCH

EXECUTE spA_GEN_LogError

END CATCH



END





but every time getting the error and my data not inserted into the database:



The UPDATE statement conflicted with the FOREIGN KEY constraint "FK_tb_vessellic_vsl_fsh_tb_lkpports_prt_fsh2". The conflict occurred in database "db_fsh_MRAEFish", table "dbo.tb_lkpports_prt_fsh", column 'ID'.



Any ideas on this?? Thank you!
Jo Pattyn
Jo Pattyn
SSCrazy
SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)

Group: General Forum Members
Points: 2740 Visits: 9899
What is the foreign key FK_tb_vessellic_vsl_fsh_tb_lkpports_prt_fsh2?



How does @ID get filled in, I only see @IDINT
Grant Fritchey
Grant Fritchey
SSC-Dedicated
SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)

Group: General Forum Members
Points: 39598 Visits: 32638
Sure sounds like you have a foreign key constrain violation. Check the data incoming against the data in the table that the error indicates. You have to have a discrepancy between the two.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
Tomm Carr
Tomm Carr
Right there with Babe
Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)

Group: General Forum Members
Points: 784 Visits: 787
You have supplied us a tremendous lack of detail to supply a definitive answer, but thanks to your somewhat convoluted naming convention, I can make a guess. There are five columns among all the ones being updated, named "vsl_prt_{First|Second|Third|Fourth|Fifth}PortID_fk". I'm guessing these are foreign keys to the tb_lkpports_prt_fsh table. Any of the new values being updated here must already exist in the "id" column of that table -- or be null. Examine those values and check against the tb_lkpports_prt_fsh table.

Tomm Carr
--
Version Normal Form -- http://groups.google.com/group/vrdbms
Todd Janes
Todd Janes
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 45
Can a lack of detail be tremendous?
Ninja's_RGR'us
Ninja's_RGR'us
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28801 Visits: 9671
Yes... never heard that expression b4 but it makes sens when you think about it.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search