Copying table

  • Hi,

    How do I copy a table from one database to another on the same server?

    Without losing the keys and depencies?

    Both database are exactly the same.

  • There must be different degrees of "exactly the same" otherwise you wouldn't need to do this...

    Seriously, though, just script out the table and then run the script against the second database. Then use the tool of your choice to copy the data across (DTS, an INSERT query, etc).

    John

  • Ya of course your right the data is not the same.

    What do you mean by scripting out?

  • I'm not clear about whether your table already exists in the second database and you just want to copy the data. If so, just use DTS or INSERT INTO or whatever. If you need to create the table first, right-click on the table in the first database is Enterprise Manager, choose Generate SQL Script, and choose your options in the dialog box. You can then run the resulting script against the second database to create the table there. I think there's also a DTS task that will copy the whole table over for you as well, if you prefer to use that method.

    John

  • O.k i did the script and run it against the second databse. It created an empty table. I will try the wizard right now.

    But that erase the primary key and dependencies. Is there a way to keep those or am I just dreaming.

  • There are lots of options in that dialog box, one of which is to script out the primary key constraint. Have a play with those options, and see if you can get it to generate the script you want.

    John

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

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