Search code examples
sqlsql-serversql-server-2008sql-server-2000sqlcmd

Moving data from SQL Server 2008 to remote SQL Server 2000, using sqlcmd


The setup:
I have two different machines, one with MS SQL Server 2008 which is my main machine and a secondary with MS SQL Server 2000. Newly generated data are stored in a specific table on the main server(2008).

The problem:
My main machine has limited storage, whereas my secondary one with the older SQL version(2000), doesn't have such kind of limitations.

A possible solution:
At least as a temporary solution, i could try to move some data, on a daily schedule, from the main machine to the secondary, using sqlcmd, run by a Windows Task Scheduler.
The largest portion of my data are stored on a single table so the idea is to "cut" them from the table on the main server and append them on a "backup/depot/storage" table on my secondary server.

What i have tried so far:
So far, i haven't been able to simultaneously connect to both servers from the main one, at least using sqlcmd. Is there a limitation for the sqlcmd to the connections it can create simultaneously?

Other possible ways:
Is there a suggested practice for that case? Would it be a good idea to write a vbs script to export from the main server and import to the secondary?

All corrections and suggestions are welcome. And thanks for your time.


Solution

  • First, link the servers. From the server you want to INSERT into, run this SQL (using any tool you want to run SQL with... SQL Server Management Studio or SQLCMD or OSQL or whatever):

    EXEC sp_addlinkedServer N'remoteSqlServer\Instance', N'SQL Server'
    EXEC sp_addlinkedsrvlogin @rmtsrvname = N'remoteSqlServer\Instance', @useself = 'FALSE', @rmtuser = N'user', @rmtpassword = N'password'
    

    Replace "remoteSqlServer\Instance" with the actual host-name\instance of the SQL Server you want to copy data FROM. Also replace the "user" and "password" with appropriate login credentials to that server.

    After that is done, you can execute SQL like the following against this server (from anywhere, including SQLCMD):

    INSERT INTO [LocalTable]
    SELECT * FROM [remoteSqlServer\Instance].[DatabaseName].[schema].[TableName]
    

    Again, this is just an example... you'd replace all those values with values appropriate to your source and destination databases (everything in the square brackets). For instance, it might look something like this:

    INSERT INTO [HistoricalData]
    SELECT * FROM [DBServer\SQL2008].[ProductionDatabase].[dbo].[CurrentData]
    

    I hope this helps.