Reputation: 143037
I have a local SQL Server Express database that I want to copy to a SQL Server database on a server. I do not have full permissions to the server, so I cannot directly attach it. Somebody told me I could do this by using the SqlBulkCopy
[MSDN] class.
I can't figure out how to use it. I haven't done enough database programming to be familiar with how this sort of thing is done.
Basically, I want to copy all the tables in one database to another. There are relationships between the tables, I don't know if that will make a difference in the copying or not. There aren't very many, so it wouldn't be a big deal to just copy the data and then manually reassign the relationships.
This is as far as I could go
var localDatabase = new SqlConnection("connection string");
var serverDatabase = new SqlConnection("other connection string");
SomehowCopyAllTables(localDatabase, serverDatabase);
but unfortunately, Mr. C# didn't want to acknowledge the existence of the SomehowCopyAllTables
method.
How can I copy all the tables from one database to another?
Upvotes: 2
Views: 538
Reputation: 14978
It might be easier to simply use Atlantis Interactive's Schema Inspector and Data Inspector rather than program it yourself. Simply compare the schema to a blank database on your current system.
Upvotes: 0
Reputation: 14787
To generate database scripts from Sql Server Management Studio:
This will generate the schemas only. If you want to do data generating scripts as well, in step 6) click the Advanced button and scroll down to the "Types of data to script" and change it from "Schema only" to "Data only" or "Schema and data"
Upvotes: 2
Reputation: 100657
Use SQL Server's Generate Scripts command within SQL Server Management Studio.
INSERT
statements for all table data selected in bullet 2.Upvotes: 4
Reputation: 8447
From my point of view, the best way is to create SQL scripts in your SQL Express and execute the generated scripts on your server. The whole data will be copied.
Upvotes: 2