I have problem when I tried to update two tables in one Store Procedure I get the SqlException could some one help me
The INSERT statement conflicted with the FOREIGN KEY constraint “FK”.
The conflict occurred in database “”, table “dbo.Users”, column
‘userID’. The statement has been terminated.
ALTER PROCEDURE [dbo].[CreateProject]
@ProjectID UNIQUEIDENTIFIER,
@UserID UNIQUEIDENTIFIER,
@ProjectName NVARCHAR(50),
@Description NTEXT,
@EstStartDate DATETIME,
@EstEndDate DATETIME,
@StatusID SMALLINT,
@Priority SMALLINT
AS
INSERT INTO DBO.Projects VALUES
(@ProjectID,@ProjectName,GETDATE(),@Description,@EstStartDate,@EstEndDate,@StatusID,@Priority)
INSERT INTO Users_projects VALUES
(@ProjectID,@UserID)
Problem is with the Foreign Key of UserID. You need to insert UserId into the Users table first. Few pointers: “createProc” procedure generally should create the ProjectId and return as an OUTPUT parameter. Also, you may want to use username as input parameter and let the proc look up the UserId.