SQL Server 2005 - 以编程方式导出表(运行 .sql 文件以重建它) [英] SQL Server 2005 - Export table programmatically (run a .sql file to rebuild it)

查看:33
本文介绍了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).

  1. 右键单击您的数据库
  2. 选择任务 > 生成脚本
  3. 按下一步,再次选择您的数据库
  4. 在选择脚本选项"屏幕上,有一个名为脚本数据的选项,它将为您的所有数据生成 SQL 插入语句.
  1. Right click your database
  2. Choose Tasks > Generate Scripts
  3. Press Next, select your database again
  4. 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")

这篇关于SQL Server 2005 - 以编程方式导出表(运行 .sql 文件以重建它)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆