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

查看:98
本文介绍了SQL Server 2005-以编程方式导出表(运行.sql文件以重建表)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带表的数据库客户有一些数据


我在办公室有另一个数据库,所有数据库都是一样的,但是我的表客户是空的


如何在SQL Server 2005(T-SQL)中创建一个sql文件,该文件将表中的所有内容都存储在第一个数据库中,客户创建了一个假设(例如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. 按Next,再次选择数据库

  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天全站免登陆