将 SQL Server Express 表迁移到 SQL Server 数据库
我有一个本地 SQL Server Express 数据库,我想将其复制到服务器上的 SQL Server 数据库。我没有服务器的完全权限,因此无法直接附加它。有人告诉我,我可以使用 来做到这一点SqlBulkCopy
[MSDN] 类。
我不知道如何使用它。我还没有进行足够的数据库编程来熟悉这类事情是如何完成的。
基本上,我想将一个数据库中的所有表复制到另一个数据库中。表之间存在关系,我不知道这是否会对复制产生影响。数量不是很多,因此只需复制数据然后手动重新分配关系也没什么大不了的。
这是我所能做到的
var localDatabase = new SqlConnection("connection string");
var serverDatabase = new SqlConnection("other connection string");
SomehowCopyAllTables(localDatabase, serverDatabase);
,但不幸的是,C# 先生不想承认 SomehowCopyAllTables
方法的存在。
如何将一个数据库中的所有表复制到另一个数据库?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 SQL Server Management Studio 中使用 SQL Server 的生成脚本命令。
INSERT
语句。Use SQL Server's Generate Scripts command within SQL Server Management Studio.
INSERT
statements for all table data selected in bullet 2.从我的角度来看,最好的方法是在 SQL Express 中创建 SQL 脚本并在服务器上执行生成的脚本。整个数据将被复制。
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.
要从 Sql Server Management Studio 生成数据库脚本:
这将仅生成模式。如果您还想执行数据生成脚本,请在步骤 6) 中单击“高级”按钮,然后向下滚动到“脚本的数据类型”,并将其从“仅架构”更改为“仅数据”或“架构和数据”
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"
只需使用 Atlantis Interactive 的 架构检查器 和 < a href="http://www.atlantis-interactive.co.uk/products/datainspector/default.aspx" rel="nofollow">数据检查器 而不是自己编程。只需将该架构与当前系统上的空白数据库进行比较即可。
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.