Creating create table script

  • Are there any system stored procedures that would allow you to simply type the name of any table from a DB and have it auto generate a Create Table Script as well as include any table dependencies in SQL Query Analyzer? Like user permissions etc.

  • This functionality is built into Enterprise Manager - right click on the table you want, select ALL TASKS then GENERATE SQL SCRIPT. Go to the OPTIONS tab for settings relating to scripting indexes, keys, triggers, user permissions etc etc

  • I know how to do it that way I can also do the same thing in QA, however I'm trying to create an application that will allow users to simply type in the table name and have a script that automatically creates the create table script using SQL. That’s why I wasn't sure if there were any system stored procedures or something that would allow me to create the script just by referencing the table name

  • You could write your own stored proc using system stored proc sp_columns to return list of cols and datatypes for the table, then build up script string from there.

  • I'm interested if you found a script for that, if not I'm interested to collaborate to make one

  • No, but press the {f8} key in query anlyzer to reveal the "tree"... drill down to the table you want, right click on it, and read the menu that appears... might want to setup "Scripting Options" from the same place to include some of those things you mentioned...

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply