是否有“脚本表为 - MERGE”?在某处起作用?
在 SSMS 2008 R2 中,当我右键单击表时,我会看到“脚本表为”,然后是插入和更新选项。但是合并呢?合并实际上就是将这两者结合在一起。
我可以获得任何可以添加该选项的工具吗? (因此,我可以编写一个合并语句,准备好添加源信息(有点像插入和更新脚本已准备好添加要插入或更新的数据)。
In SSMS 2008 R2, when I right click on a table I see "Script Table as" then options for Insert and Update. But what about Merge? Merge is really just the two of these together.
Is there any tool I can get that will add that option? (So I can script a merge statement ready for me to add in source information (kind of like the Insert and Update scripts are ready for adding the data to insert or update).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
SSMS 中没有执行此类操作的内置功能(我想通过外部插件可能可以实现)。
有一个程序
sp_GenMerge
(根据 MIT 许可证授权)由 Michał Gołoś 允许使用数据编写表脚本作为合并语句。示例场景:
基本 SP 调用(它支持更多选项 - 请参阅文档):
输出:
并将脚本行作为 XML 有效负载:
There is no built-in functionality in SSMS that performs such operation(I guess it may be possible with external plugin).
There is a procedure
sp_GenMerge
(licensed under MIT license) written by Michał Gołoś that allows to script table with data as merge statement.Sample scenario:
Basic SP call(it supports more options - see doc):
Output:
And scripted rows as XML payload:
GitHub 上有一个非常有用的脚本,我一直在使用它并取得了巨大的成功。
使用表数据生成 SQL MERGE 语句< /a>
用例:
它是如何工作的?
生成的 MERGE 语句填充目标表以匹配源数据。这包括删除源中不存在的任何多余行。
当执行生成的 MERGE 语句时,根据是否找到匹配来应用以下逻辑:
用法:
示例:
要生成包含 Person.AddressType 表中所有数据(不包括 ModifiedDate 和 rowguid 列)的 MERGE 语句:
输出:
There is a very useful script on GitHub that I've been using with great success.
Generate SQL MERGE statements with Table data
Use Cases:
How Does It Work?
The generated MERGE statement populates the target table to match the source data. This includes the removal of any excess rows that are not present in the source.
When the generated MERGE statement is executed, the following logic is applied based on whether a match is found:
Usage:
Example:
To generate a MERGE statement containing all data within the Person.AddressType table, excluding the ModifiedDate and rowguid columns:
OUTPUT:
直到我知道你不能,但有一些提示:
如何编辑SSMS 脚本表作为模板?
Until i know you can´t but there are some tips:
How to edit SSMS Script Table As templates?