• RBarryYoung (8/30/2012)


    As someone who has written many "automation" procedures like this, this is a good first effort emreguldogan. Here are some improvements that you could make:

    1. Removal of the Cursor and the While loop.

    (you don't need them if you use one of the string aggregation tricks)

    2. Account for the possibility of spaces in the table and column names.

    (put brackets ("[..]") around the names)

    3. Actually create the procedure for the user.

    (Instead of "print", make a big string and then execute it with "EXEC(@string);".)

    If you want to see a good example of how #1 and #3 are done, take a look at this procedure: http://www.sqlservercentral.com/scripts/Administration/69737/

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]