Scripting a table schema using T-SQL only

  • Hi

    I've been looking for a script that would do this, as an Oracle DBA has asked to see if I knew.

    He says there is a simple command he uses in Oracle like 'show' or something which does it but there isn't anything like that in MSSQL.

    Does anybody know of a script that would do it?

    Thanks

  • In Query Analyzer in Object Browser (press F8 to open it) right-click on the table, then choose "Script Object ..." - whatever you need.

    _____________
    Code for TallyGenerator

  • Thanks Sergiy

    Problem is he wants to run it from a stored proc, so it has to be all t-sql.

    I have found some code to script everything but it's difficult to extract just the table part.

    The code is below.

    http://www.nigelrivett.net/DMO/DMOScriptAllDatabases.html

    Paul

  • What's your point?

    Create another table with the same structure as existing one?

    Then just do this:

    SELECT *

    INTO dbo.NewTable

    FROM dbo.ExistingTable

    WHERE 1=0

    If not just explain what are you trying to achieve.

    _____________
    Code for TallyGenerator

  • sp_Help tablename is what most folks are looking for.  Similar to "describe" in Oracle.  Lemme know if that's not quite what you wanted.

    --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)

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

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