Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SELECT INTO or CREATE TABLE

SELECT INTO or CREATE TABLE

Scheduled Pinned Locked Moved Database
databasequestioncsharphelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bxlorenz
    wrote on last edited by
    #1

    I have a SQL 2005 database and a SQL 2008 database. I want a simple SQL statement that will create/copy a table and its contents from 2005 into 2008 that I can use in a C# program. I know I can export using Mgmt Studio but I want to do in a a program. I am able to perform a SELECT INTO [MyDatabase2].[dbo].[mytable] SELECT * FROM [Mydatabase1].[dbo].[mytable] when they exist in different databases in the same machine and only in the same Database Instance but how do I across multiple instances or multiple machines. Can anyone help ? Thanks

    B 1 Reply Last reply
    0
    • B bxlorenz

      I have a SQL 2005 database and a SQL 2008 database. I want a simple SQL statement that will create/copy a table and its contents from 2005 into 2008 that I can use in a C# program. I know I can export using Mgmt Studio but I want to do in a a program. I am able to perform a SELECT INTO [MyDatabase2].[dbo].[mytable] SELECT * FROM [Mydatabase1].[dbo].[mytable] when they exist in different databases in the same machine and only in the same Database Instance but how do I across multiple instances or multiple machines. Can anyone help ? Thanks

      B Offline
      B Offline
      Blikkies
      wrote on last edited by
      #2

      Use this to connect to other server

      EXEC sp_addlinkedsrvlogin 'server', 'false', 'userLocal', 'userRemote', 'remotePassword'

      Code should look like this:

      SELECT INTO [server].[MyDatabase2].[dbo].[mytable] FROM [Mydatabase1].[dbo].[mytable]

      modified on Friday, September 25, 2009 2:06 AM

      B 1 Reply Last reply
      0
      • B Blikkies

        Use this to connect to other server

        EXEC sp_addlinkedsrvlogin 'server', 'false', 'userLocal', 'userRemote', 'remotePassword'

        Code should look like this:

        SELECT INTO [server].[MyDatabase2].[dbo].[mytable] FROM [Mydatabase1].[dbo].[mytable]

        modified on Friday, September 25, 2009 2:06 AM

        B Offline
        B Offline
        bxlorenz
        wrote on last edited by
        #3

        Blikkies, Thanks for the info. Just a couple follow up questions. So on the 2005 SQLExpress Server I have an instance of SQLEXPRESS and on 2008 SQL I have an DB instance of MY2008DB I would do the following if I am running on the 2008 system. EXEC sp_addlinkedsrvlogin '\\MY2005Server\SQLEXPRESS', 'false', 'sa', 'sa', 'sa' SELECT INTO [MyDatabase2].[dbo].[mytable] FROM [\\MY2005Server\SQLEXPRESS].[Mydatabase1].[dbo].[mytable] and if I was running this on the 2005 server it would be the opposite ? EXEC sp_addlinkedsrvlogin '\\MY2008Server\MY2008DB', 'false', 'sa', 'sa', 'sa' SELECT INTO [\\MY2008Server\MY2008DB].[MyDatabase2].[dbo].[mytable] FROM [Mydatabase1].[dbo].[mytable] Or how does that work with the DB Instance name ? thanks

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups