简体   繁体   English

如何在DML(SQL脚本)中从SQL Server 2008.2010导出数据?

[英]How to export data from SQL Server 2008.2010 in DML (SQL script)?

Is there a tool or special query to do that. 有没有工具或特殊查询来做到这一点。 I'm not an database administrator. 我不是数据库管理员。

Here are the steps to generate the scripts from a database along with data. 以下是从数据库生成脚本以及数据的步骤。 The screenshots were taken using SQL Server 2012 Management Studio but I believe that the steps are similar for SQL Server 2008 as well. 截图是使用SQL Server 2012 Management Studio拍摄的,但我相信SQL Server 2008的步骤也是类似的。

  • Connect to the instance in which you would like to scrip the database along with data. 连接到您希望将数据库与数据一起编写的实例。
  • Right-click on the database and select the option Tasks --> Generate Scripts... 右键单击数据库,然后选择“ Tasks --> Generate Scripts... ”选项Tasks --> Generate Scripts...

任务生成脚本

  • On the Generate and Publish Scripts wizard, click Next button. 在“ 生成并发布脚本”向导上,单击“ Next按钮。

介绍

  • On the Choose objects step, I have left the default selection Script entire database and all database objects checked. 在“ 选择对象”步骤中,我保留了默认选择Script entire database and all database objects检查了Script entire database and all database objects You can also select the option Select specific database objects and pick the objects of your choice. 您还可以选择Select specific database objects选项并选择您选择的对象。

选择对象

  • On the Set Scripting Options step, select the path where you would like to save the script. 在“ 设置脚本选项”步骤中,选择要保存脚本的路径。 Click on the Advanced button. 单击“ Advanced按钮。

设置脚本选项

  • On the Advanced Scripting Options dialog, scroll down to the option Types of data to script . 在“ 高级脚本选项”对话框中,向下滚动Types of data to script ”选项。 By default, this is set to Schema only , which means it will generate only the create object statements. 默认情况下,它仅设置为Schema only ,这意味着它将仅生成create object语句。 If you want both object creation script along with data, select the option Schema and data . 如果要同时创建对象创建脚本和数据,请选择“ Schema and data ”选项。 Click OK on the Advanced Scripting Options dialog and click Next on the Set Scripting Options step 在“ 高级脚本选项”对话框中单击“ 确定”然后在“ 设置脚本选项”步骤上单击“ 下一步

高级脚本选项

  • On the Summary step, it will show all the options that you had selected. 摘要步骤中,它将显示您选择的所有选项。 Click Next . 单击下一步

摘要

  • On the Save or Publich Scripts step, if everything goes well you will see Success status appear against each object and the script should be saved to the location that you specified on the Set Scripting Options step. Save或Publich Scripts步骤中,如果一切顺利,您将看到针对每个对象显示成功状态,并且脚本应保存到您在Set Scripting Options步骤中指定的位置。

保存或发布脚本

Scripting the entire AdventureWorks database turned to be a huge 522 MB script file! 脚本整个AdventureWorks数据库变成了一个巨大的522 MB脚本文件!

Hope that helps. 希望有所帮助。

Do you mean generating data script? 你的意思是生成数据脚本吗? If it is so then simply right click on the database name -Generate Scripts. 如果是这样,那么只需右键单击数据库名称-Generate Scripts。 In the advanced option in the wizard you get to choose "Type Of data script to add". 在向导的高级选项中,您可以选择“要添加的数据类型脚本”。 Select data only there and you can get the data script 只在那里选择数据,您就可以获得数据脚本

to what format? 什么格式? are you only referring to 1 table or the whole database? 你只是指1个表还是整个数据库?

if you are exporting to an excel file from 1 table then all you have to do is run a sql query statement to display all records then highlight all rows thru clicking on the top most right space of the grid and right click copy with column headers. 如果要从1个表导出到excel文件,那么您所要做的就是运行sql查询语句以显示所有记录,然后通过单击网格的最右上方空间突出显示所有行,并右键单击带有列标题的复制。

open excel and paste. 打开excel并粘贴。

should be good to go. 应该好好去。

Have you tried using SSMS tool pack ? 您是否尝试过使用SSMS工具包 It is one of the best addins for SSMS. 它是SSMS最好的插件之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM