create table script

  • hey,

    how do i create an sql script to create a table?

    foreignkeys, constraints, owner, etc.

    i want to run a procedure that loops, gets all the tables and create them with all the works.

     

  • Never looked into any scripts for this particular job personally.

    I use enterprise manager by right clicking on the database and selecting ALL TASKS/ GENERATE SCRIPTS and then picking from the options available.

    Quick, easy and always accurate I have found.


    ------------------------------
    The Users are always right - when I'm not wrong!

  • Chris:

    What are you going to be looping on?  Do you have tables that mimic the sys tables that contain table defs, owners, constraints, etc.?  If you loop on the sys tables, trying to dynamically build a CREATE TABLE string, you will get errors upon each execution, because these objects already exist.

    If you are just trying to generate scripts to create the existant DB objects in another DB, this would be easy enough to do by looping through the appropriate sys tables in a SP and possibly loading another table with the script necessary to do the actual creation.

    Give us a little more information on what you are trying to accomplish.

    Thanks!

    Allen Shannon

  • There is a utility that does this. If the upgrade tools have been installed it can be found in \program files\microsoft sql server\mssql\upgrade\scptxfr.exe  Run with /? to see all the command arguments, I would use...

    "c:\program files\microsoft sql server\mssql\upgrade\scptxfr.exe"

    /s <servername> /P <password> /d northwind /f northwind.sql

     

Viewing 4 posts - 1 through 3 (of 3 total)

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