title: Explicit value must be specified for identity column in table when IDENTITY_INSERT is set to ON
body: <p>I have tables called <code>Table_Stories</code> and <code>Table_Images</code> in my database which are connected with keys. I insert values into them with a stored procedure I created.</p>
  
  <pre><code>CREATE TABLE [dbo].Table_Stories
  (
      [StoryID] INT NOT NULL IDENTITY(1, 1) PRIMARY KEY,
      [ID] INT FOREIGN KEY REFERENCES Table_Users(ID),
      [StoryText] NVARCHAR(120),
      [imgID] INT FOREIGN KEY REFERENCES Table_Images (imgID)
  )
  </code></pre>
  
  <p>CODE:</p>
  
  <pre><code>CREATE PROCEDURE UserStory  
      @ID [INT],
      @storyText [NVARCHAR](120),
      @img [VARCHAR](MAX)
  AS
  BEGIN
      DECLARE @StoryID INT, @ImageID INT;
  
      INSERT INTO Table_Images ([img]) VALUES (@img)
  
      SET @ImageID = SCOPE_IDENTITY();
  
      INSERT INTO Table_Stories ([ID], [StoryText], [imgID]) 
      VALUES (@ID, @storyText, @ImageID)
  
      SET @StoryID = SCOPE_IDENTITY();
  
      INSERT INTO Table_Stories ([StoryID]) 
      VALUES (@StoryID)
  
      INSERT INTO dbo.imagesInStories (StoryID, imgID)
      VALUES (@StoryID, @ImageID);
  
      SELECT * 
      FROM Table_Stories 
      WHERE StoryID = @StoryID AND imgID = @ImageID;
  END
  </code></pre>
  
  <p>I run:  </p>
  
  <pre><code>exec UserStory 1, 'I welcom you to my trip', 'Chadmie.jpg'
  </code></pre>
  
  <p>and get this error : </p>
  
  <blockquote>
    <p>Msg 545, Level 16, State 1, Procedure UserStory, Line 14 [Batch Start Line 291]<br>
    Explicit value must be specified for identity column in table 'Table_Stories' either when IDENTITY_INSERT is set to ON or when a replication user is inserting into a NOT FOR REPLICATION identity column.</p>
  </blockquote>
  
  <p>I don't understand what that error means and how to fix it.</p>
  
  <p>p.s
  I cant insert all the sql code here (not as I did) its taking me too much time due to the red error that is showing no matter what I do trying to fix the question code.</p>