Hello, I have two Database, DB1 and DB2. How can I transfer data of DB1 specific table to DB2 in SQL Server 2000?
A:
Right click on DB2 and Tasks-> Import will start the DTS Wizard. It's pretty simple.
Chad Grant
2009-05-06 07:27:42
A:
Some additional context about this transfer would be useful. For example, is this a one-off transfer, a regular transfer, something you want to maintain for each transaction in DB1 or something else.
I'm going to assume this is a one-off or periodic occurance and, as such, I'd suggest Data Transformation Services (DTS) in SQL Server 2000:
Martin Peck
2009-05-06 07:28:03
A:
If you need to do this through code (the .NET tag), then SqlBulkCopy
is your friend -ideally when mixed with ExecuteReader
on the source. Like so:
using (SqlConnection connSource = new SqlConnection(csSource)) // source db
using (SqlCommand cmd = connSource.CreateCommand())
using (SqlBulkCopy bcp = new SqlBulkCopy(csDest)) { // destination db
bcp.DestinationTableName = "SomeTable"; // destination table
cmd.CommandText = "SELECT * FROM [Foo]"; // source table
cmd.CommandType = CommandType.Text;
connSource.Open();
using(SqlDataReader reader = cmd.ExecuteReader()) {
bcp.WriteToServer(reader);
}
}
Marc Gravell
2009-05-06 07:57:32