Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3697812
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:54:19+00:00 2026-05-19T04:54:19+00:00

I have an issue with the below stored procedure. It runs fine as long

  • 0

I have an issue with the below stored procedure. It runs fine as long as I don’t uncomment the last insert INSERT. If I were to uncomment the last INSERT, I get the following error:

Msg 547, Level 16, State 0, Procedure
InsertRecipeWithTags, Line 42 The
INSERT statement conflicted with the
FOREIGN KEY constraint
“FK_Tag_TagRecipe”. The conflict
occurred in database “RecipeBox”,
table “RecipeDetails.Tag”, column
‘tagID’. The statement has been
terminated.

For clarification, I have three tables:

recipe(id, title, introduction, directions)
recipeTag(id, recipeID, tagID)
tag(id, name)

So if I try to insert into the recipeTag table I get the above error. Please advise.

Thanks.

CREATE PROCEDURE [RecipeDetails].[InsertRecipeWithTags]
/*
    variables that map to columns
*/
@title varchar(50),
@intro varchar(255),
@directions varchar(2200),
@ingredients varchar(2200),
@difficulty varchar(6), /*need check constraint setting difficulty to "beginner" "medium" or "expert"*/
@prepTimeHour tinyint,
@prepTimeMinute tinyint,
@inactiveTimeHour tinyint,
@inactiveTimeMinute tinyint,
@servings tinyint,
@photo varbinary(MAX),
@tagName varchar(50),
@tagdescription varchar(255)

AS

BEGIN
    SET NOCOUNT ON;

    DECLARE @RecipeID int, @TagID int

    INSERT INTO RecipeDetails.Recipe (title, intro,directions, ingredients, difficulty, 
    prepTimeHour, prepTimeMinute, inactiveTimeHour, inactiveTimeMinute, servings, photo)
    VALUES (@title, @intro,@directions, @ingredients, @difficulty, @prepTimeHour, @prepTimeMinute,
    @inactiveTimeHour, @inactiveTimeMinute, @servings, @photo)

    SELECT @RecipeID=SCOPE_IDENTITY()

    SELECT * FROM RecipeDetails.Recipe WHERE recipeID = @RecipeID;

    INSERT INTO RecipeDetails.Tag (name, description)
    VALUES (@tagName, @tagdescription)

    SELECT @TagID=SCOPE_IDENTITY()

    SELECT * FROM RecipeDetails.Tag WHERE tagID = @TagID;

    /*INSERT INTO RecipeDetails.TagRecipe (tagID, recipeID)
    VALUES (@RecipeID, @TagID)*/
END
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:54:19+00:00Added an answer on May 19, 2026 at 4:54 am

    Reverse the order?

    INSERT INTO RecipeDetails.TagRecipe (tagID, recipeID)
    VALUES (@TagID, @RecipeID)
    

    You had then the wrong way around

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a strange, sporadic issue. I have stored procedure that returns back 5
I have a weird issue where I have a stored procedure that is inserting
I have been facing issue with sphinx result set for string attribute. Below is
I have an issue and I have looked long and hard over the Internet
Just want to get some views/possible leads on an issue I have. I have
I have a stored procedure in Oracle Database 10g where my input is a
I've the following MS SQL stored procedure. I need to sort the results without
I have a stored procedure that has a parameter called UserName and in my
I haven't solved this issue by using the stored procedure, yet we've decided to
I've long been a fan of Stored Procedure Keyboard Accelerators, as described in this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.