SQL Server 2005 - 以编程方式导出表(运行 .sql 文件以重建它)
我有一个带有表的数据库,客户有一些数据
我在办公室有另一个数据库,一切都一样,但我的表客户是空的
如何在 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?
推荐答案
此功能已内置到 Sql Server Management Studio 2008 中.
This functionality is already built in to Sql Server Management Studio 2008.
只需下载试用版,然后只安装客户端工具(不应过期).使用 Management Studio 2008 连接到您的 2005 数据库(向后兼容).
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).
- 右键单击您的数据库
- 选择任务 > 生成脚本
- 按下一步,再次选择您的数据库
- 在选择脚本选项"屏幕上,有一个名为脚本数据的选项,它将为您的所有数据生成 SQL 插入语句.
- Right click your database
- Choose Tasks > Generate Scripts
- Press Next, select your database again
- On the 'Choose Script Options' screen, there is an option called Script Data which will generate SQL insert statements for all your data.
(注意:对于 SQL Server Management Studio 2008 R2,该选项称为要编写脚本的数据类型",是常规"部分的最后一个.选项为仅数据"、架构和数据"以及仅模式")
(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")
相关文章