3

是否可以仅使用 Management Studio 或 Visual Studio 为 SQL Server 记录生成单独的 INSERT 语句?

您可以“生成脚本”以获取 SSMS 中整个表的数据,而不仅仅是单行或过滤的一组行。

在 Visual Studio 2012 中,如果您在 SQL Server 对象资源管理器中选择表数据,您会得到一个“脚本”按钮,该按钮会为网格结果生成插入语句,即 200、1000 或“全部”记录 - 但我可以'找不到像 SSMS 中那样的“WHERE”过滤器。

有什么我错过的技巧吗?SSMS 或 VS 都会很棒 - 理想情况下,我能够过滤特定的行或一组行,然后专门为这些行生成 INSERT 语句。

有 SSMS Toolpack、RedGate、Toad,我敢肯定还有一些其他付费产品可以做到这一点,但我希望有一些内置的方法。

(这个问题之前已经解决过,但我能找到的都是在 2012 年之前,所以从那时起可能已经引入了一些东西)。

4

2 回答 2

1

Yes - use the Generate Scripts Task.

Right-Click on the DB in the Object Explorer window. Then select Tasks and Generate Scripts.

Select the object(s) you want to script and click next. Then click Advanced and go to "Types of Data to Script". Choose Data Only or Schema and Data (Theses selections will build your insert statements).

It sounds like you already know about this though and I'm not aware of any way to apply a filter on what is generated.

Here is a script I found on SqlServerCentral. Although this was built for sql server 2k, its worth a look:

http://vyaskn.tripod.com/code/generate_inserts.txt

于 2013-10-15T21:50:23.527 回答
0

可能这个答案为时已晚,最近开始使用2012的人会有所帮助。

在 VS 2012 中,转到 SQL Server 对象资源管理器。选择数据库,然后列出该数据库中的表。然后选择您要创建的脚本的特定/特定表。然后右键单击该表并选择 ViewData 选项。然后在该显示/结果 Grid 的顶部,Maxrow 的右侧,您可以看到两个图标。两者都在生成脚本。一个在屏幕上,另一个进入文件。

于 2013-12-31T09:32:48.187 回答