CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 1999
    Location
    Michigan, USA
    Posts
    7

    Copy SQL Server table

    I have two SQL Server databases with the same table. One of the tables gets updated by the user. How can I copy the updated table to the table in the other database when a user clicks on a VB cmd button "update table".

    Thanks for your help.



  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Copy SQL Server table

    Execute the following SQL

    sSQL = "insert into db2.dbo.table2 select * from db1.dbo.table1"
    conn.Execute sSQL

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    May 1999
    Location
    Michigan, USA
    Posts
    7

    Re: Copy SQL Server table

    Iouri,

    Will this code append to the existing rows or replace all the rows? I need to replace all existing rows. Essentially, I want to re-create the table.

    Thanks!


  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Copy SQL Server table

    Re-create? Then you can drop all from first table, and after that insert form the second.

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  5. #5
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Copy SQL Server table

    It will append rows. As Cimperiali said you can delete records from the table and then append.

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured