Results 1 to 12 of 12
  1. #1
    Join Date
    Jun 2007
    Posts
    44

    Unanswered: About copying table..

    just wondering how can i script out so that i can copy a table from a database but not the data itself..
    .

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    You can do this using SQL-DMO scripts, or by using the GUI tools (like Query Analyzer, SQL Enterprise Manager, or SQL Server Management Studio). The exact mechanics vary from one tool to another, but if you tell us which tool your are using or look in SQL Server Books Online you can find out how to do it.

    -PatP

  3. #3
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    fyi: DMO is deprecated in 2005 - the new api is SMO, which is managed. DMO is native.

    also, here's a console app to do this if you want to automate it from the cmd line: http://www.codeplex.com/scriptdb

  4. #4
    Join Date
    Jun 2007
    Posts
    44

    About copying table

    i am using management studio and query analyzer.

  5. #5
    Join Date
    Jan 2004
    Location
    In a large office with bad lighting
    Posts
    1,040
    In management studio, once you have a list of tables in either Object explorer or the Summary tab, right mouse click on the table and move the mouse pointer to "Script Table as", "CREATE", and "New Query Editor Window" in the dropdown boxes that appear.

    -- This is all just a Figment of my Imagination --

  6. #6
    Join Date
    Sep 2003
    Location
    New York, NY
    Posts
    136
    and here's a quick and dirty way

    SELECT * INTO NEW_TABLE FROM OLD_TABLE WHERE 1=0

  7. #7
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    no indexes, no constraints etc..
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  8. #8
    Join Date
    Jun 2007
    Posts
    44

    About Copying table

    hey rohit...
    is such this practice bad?

  9. #9
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Quote Originally Posted by drek_01
    hey rohit...
    is such this practice bad?

    Define Bad
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  10. #10
    Join Date
    Jun 2007
    Posts
    44
    is there any issue with that ..thats what i mean

  11. #11
    Join Date
    Sep 2003
    Location
    New York, NY
    Posts
    136
    select into creates a new table and populates it with the resultset of the SELECT statement. good for doing table backups.

    but if you want to make a copy of the table (with indexes, constraints etc), then creating a script and then executing is the way to go.
    hope i explicated it correctly.
    Last edited by rohitkumar; 01-09-08 at 17:03.

  12. #12
    Join Date
    Jun 2007
    Posts
    44
    That should do it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •