SQL Server 2005 - 以编程方式导出表(运行 .sql 文件来重建它)
我有一个数据库,其中有一个包含一些数据的客户表
我办公室里有另一个数据库,一切都一样,但我的表 Customers 是空的
如何在 SQL Server 2005 (T-SQL) 中创建一个 sql 文件,该文件从第一个数据库中获取 Customers 表上的所有内容,创建一个 buildcustomers.sql,我压缩该文件,通过网络复制它,执行它在我的 SQL Server 中,瞧! 我的桌子顾客已满
我怎样才能对整个数据库做同样的事情?
I have a database with a table Customers that have some data
I have another database in the office that everything is the same, but my table Customers is empty
How can I create a sql file in SQL Server 2005 (T-SQL) that takes everything on the table Customers from the first database, creates a, let's say, buildcustomers.sql, I zip that file, copy it across the network, execute it in my SQL Server and voila! my table Customers is full
How can I do the same for a whole database?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(7)
我只是想为 Sql Server Management Studio 2008 添加一些屏幕截图。使用前面描述的步骤是正确的。 当您有“生成并发布脚本”时 -> “设置脚本选项”,然后按“高级”查看脚本选项:
![在哪里可以找到高级脚本选项]:图像丢失,因为我没有正确的声誉:(
对于 Sql Server Management Studio 2008,包含数据的选项是“类型”数据到脚本'
![脚本数据类型]:图像丢失,因为我没有正确的声誉:(
I just like to add some screen shoots for Sql Server Management Studio 2008. It is correct to use the steps describe previously. When you have the 'Generate and Publish Script' -> 'Set Script Options' then press Advance to see script options:
![Where to find Advanced script options]: image missing because I do not have the right reputation :(
For Sql Server Management Studio 2008 the option to included data is 'Types of data to script'
![Types of data to script]: image missing because I do not have the right reputation :(
使用
bcp
(从命令行)连接到网络文件,然后将其恢复。例如
非常快速且轻松地嵌入代码中。 (我已经围绕这个命令构建了一个数据库备份(恢复)系统。
Use
bcp
(from the command line) to a networked file and then restore it.e.g.
Very quick and easy to embed within code. (I've built a database backup(restore) system around this very command.
此功能已内置于 Sql Server Management Studio 2008 中。
只需下载 试用并仅安装客户端工具(不应过期)。 使用 Management Studio 2008 连接到 2005 数据库(向后兼容)。
(注意:对于 SQL Server Management Studio 2008 R2,该选项称为“要编写脚本的数据类型”,是“常规”部分的最后一个选项。选项包括“仅数据”、“架构和数据”和“仅架构” ")
This functionality is already built in to Sql Server Management Studio 2008.
Just download the trial and only install the client tools (which shouldn't expire). Use Management Studio 2008 to connect to your 2005 database (its backwards compatible).
(Note: for SQL Server Management Studio 2008 R2, the option is called "Types of data to script" and is the last one in the General section. The choices are "data only", "schema and data", and "schema only")
您可以查看以下文章,了解如何使用 SQL Server 本机工具和第三方工具来执行此操作:SQL Server 批量复制和批量导入导出技术
免责声明:我在 ApexSQL 担任支持工程师
希望这有帮助
You can check the following article to see how you can do this by using both SQL Server native tools and the third party tools: SQL Server bulk copy and bulk import and export techniques
Disclaimer: I work for ApexSQL as a Support Engineer
Hope this helps
如果两个数据库驻留在同一 SQL Server 实例中,即使用相同的连接,则此 SQL 可能会有所帮助:
If both databases resides in the same instance of SQL Server, ie use same connection, this SQL might be helpful:
您始终可以将数据从“客户”表导出到 Excel 文件,然后将该数据导入到“客户”表中。
导入/导出数据:
You could always export the data from the Customers table to an Excel file and import that data into your Customers table.
To import/export data:
对于 SQL Server 2005 中作为 SQL 脚本的 Data Expoer,
http://blog.sqlauthority.com/2007/11/16/sql-server-2005-generate-script-with-data-from-database-database-publishing -向导/
For Data Expoer as SQL script in SQL server 2005,
http://blog.sqlauthority.com/2007/11/16/sql-server-2005-generate-script-with-data-from-database-database-publishing-wizard/