locked
Create a stored procedure within another stored procedure RRS feed

  • Question

  • Hello guys.

    I want to create a stored procedure within another stored procedure like following code.

    ALTER PROC USP_CRE_USP_INS_TEST
    AS
    BEGIN
      EXEC('CREATE PROCEDURE USP_INS2_TEST
    AS 
    BEGIN
      SELECT * FROM TEST
    END')
    EXECUTE USP_INS2_TEST
    END

    When i execute the code i hava following error

    The module 'USP_CRE_USP_INS_TEST' depends on the missing object 'USP_INS2_TEST'. The module will still be created; however, it cannot run successfully until the object exists.

    Thank u.

    Please Help Me.


    • Edited by Kalman Toth Thursday, March 28, 2013 7:28 PM Long title
    Thursday, March 28, 2013 3:40 PM

Answers

  • NO.

    No, no, no.

    No.

    You do not want to create a stored procedure from within another one.

    If you are considering this then you have something wrong in your design.

    Please let us know what you are trying to achieve and why


    George
    blog | twitter

    • Proposed as answer by Naomi N Thursday, March 28, 2013 3:45 PM
    • Marked as answer by Allen Li - MSFT Friday, April 5, 2013 7:49 AM
    Thursday, March 28, 2013 3:42 PM
    Answerer

All replies

  • NO.

    No, no, no.

    No.

    You do not want to create a stored procedure from within another one.

    If you are considering this then you have something wrong in your design.

    Please let us know what you are trying to achieve and why


    George
    blog | twitter

    • Proposed as answer by Naomi N Thursday, March 28, 2013 3:45 PM
    • Marked as answer by Allen Li - MSFT Friday, April 5, 2013 7:49 AM
    Thursday, March 28, 2013 3:42 PM
    Answerer
  • Hi mr gvee

    i want to create a stored procedure that get name of database and create four stored procedure(INSERT,UPDATE,DELETE,SELECT) for every table.

    for Introduction i should know how can i create a stored procedure within mother stored procedure.

    Please Help me.

    Thank u.

    Thursday, March 28, 2013 4:05 PM
  • I don't think you should run such generator from inside SQL Server itself.

    BTW, you may want to look at this free product MyGeneration

    http://download.cnet.com/MyGeneration/3000-10250_4-10343918.html?tag=mncol%3bpop&cdlPid=10783348


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog

    Thursday, March 28, 2013 4:14 PM