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 8632917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:25:02+00:00 2026-06-12T09:25:02+00:00

I have a table into which I have to insert data if a particular

  • 0

I have a table into which I have to insert data if a particular key is not present. I decided to write a stored procedure to insert data. What I want to do is:

  1. Create a stored procedure.
  2. Insert a bunch of rows using the stored procedure.
  3. Drop the stored procedure.

I want to do all this in a single script file so that no one ever knows that the stored procedure existed.

Here is what I have:

Create

CREATE PROCEDURE My_Proc(@key varchar(10))
  AS
  BEGIN
  IF NOT EXISTS (SELECT * FROM [dbo].[My_Table] WHERE [key] = @key)
    INSERT INTO [dbo].[My_Table] (key, created, modified)
    VALUES (@key, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
  END

Insert

EXECUTE My_Proc 99241
GO
EXECUTE My_Proc 99242
GO
EXECUTE My_Proc 99243
GO

Drop

DROP PROCEDURE My_Proc

Now I right click on my database in SQL Server Management Studio, click on New Query and paste the above query. I get the following output:

(1 row(s) affected)

(1 row(s) affected)
Msg 217, Level 16, State 1, Procedure My_Proc, Line 9
Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32).

(1 row(s) affected)
Msg 217, Level 16, State 1, Procedure My_Proc, Line 9
Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32).

I am unable to figure out what is causing the error. Also, When I highlight the specific EXECUTE command on SSMS like so EXECUTE My_Proc 99241 the data gets inserted without any error.

  • 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-06-12T09:25:02+00:00Added an answer on June 12, 2026 at 9:25 am

    You need a GO after your Create procedure. I believe the first “EXECUTE My_Proc 99241” is getting included as part of the procedure because of the missing GO, so basically you have a recursive call.

    Create Procedure statement (as well as functions and similar statements) takes everything to the end of the batch, which is why they have to be followed by “GO” or end of the file.

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

Sidebar

Related Questions

I have this query to insert data which is not present inside mytab from
I have a bunch of data which will insert into a table. This issue
I have a table into which new data is frequently inserted. I need to
I have a table which i want to store all the outputs into one
I have a table A into which I am inserting data. Then some calculation
I want to insert data into a table, then if the table already has
I have a method insert() which inserts a list of values into a table
I have a table A. I insert data into table A through a user
I have some problem whith such mysql_query INSERT INTO table VALUES ('', CURDATE()-1) why
I have the following table structure, which is imported into an Entity Framework project:

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.