sql 服务器 #region
我可以在 sql server 编辑器中创建区域(如 C# 中的 #region
和 #endregion
)吗?
Can I create regions in sql server editor (like #region
and #endregion
in C#) ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
不是真的,抱歉!但是...
添加
begin
和end
.. 在begin
上添加注释会创建如下所示的区域...不过有点黑客行为!否则你只能展开和折叠你就可以' t 规定应该展开和折叠的内容。离不开第三方工具,例如 SSMS 工具包。
Not really, Sorry! But...
Adding
begin
andend
.. with a comment on thebegin
creates regions which would look like this...bit of hack though!Otherwise you can only expand and collapse you just can't dictate what should be expanded and collapsed. Not without a third-party tool such as SSMS Tools Pack.
(我是 SSMS 的 SSMSBoost 插件的开发人员)
我们最近在 SSMSBoost 插件中添加了对此语法的支持 -在。
它还具有在打开脚本时自动“识别”区域的选项。
(I am developer of SSMSBoost add-in for SSMS)
We have recently added support for this syntax into our SSMSBoost add-in.
It has also an option to automatically "recognize" regions when opening scripts.
BEGIN...END 有效,您只需添加注释部分即可。最简单的方法是添加部分名称!另一种途径是添加评论块。见下文:
BEGIN...END works, you just have to add a commented section. The easiest way to do this is to add a section name! Another route is to add a comment block. See below:
这只是在查询编辑器中使用文本缩进的问题。
扩展视图:
折叠视图:
< img src="https://i.sstatic.net/kQi6O.jpg" alt="折叠">
It is just a matter of using text indentation in the query editor.
Expanded View:
Collapsed View:
Sql Server Management Studio 中并不是开箱即用的,但它是 Sql Server Management Studio 的一个功能好SSMS工具包
Not out of the box in Sql Server Management Studio, but it is a feature of the very good SSMS Tools Pack
不,T-SQL 语言中不存在#region。
您可以使用 begin-end 块进行代码折叠:
我不确定我是否会建议使用它们,除非代码不能通过其他方式进行可接受的重构!
No, #region does not exist in the T-SQL language.
You can get code-folding using begin-end blocks:
I'm not sure I'd recommend using them for this unless the code cannot be acceptably refactored by other means though!
我使用了类似于 McVitie 的技术,并且仅在相当长的存储过程或脚本中使用。我将像这样分解某些功能部分:
此方法在管理工作室中显示得相当好,并且对于审查代码非常有帮助。折叠的部分看起来有点像:
我实际上更喜欢这种方式,因为我知道我的
BEGIN
与这种方式的END
匹配。I've used a technique similar to McVitie's, and only in stored procedures or scripts that are pretty long. I will break down certain functional portions like this:
This method shows up fairly nice in management studio and is really helpful in reviewing code. The collapsed piece looks sort of like:
I actually prefer it this way because I know that my
BEGIN
matches with theEND
this way.另一种选择是,
如果您的目的是分析查询,Notepad+ 具有有用的 Sql 自动包装器。
Another option is
if your purpose is analyse your query, Notepad+ has useful automatic wrapper for Sql.
如果您不想向 SSMS 添加插件,您可以这样做并获取可折叠和可展开的代码块
您不必添加 #region 和 #endregion,只需在其位置指定描述即可之前已经建议过。
信用:https://stackoverflow.com/a/22633580/1165173
If you don't want to add a plugin to SSMS you can do it like this and get the collapsible and expandable code blocks
You don't have to add #region and #endregion and can just specify the description in it's place as others have suggested previously.
Credit: https://stackoverflow.com/a/22633580/1165173
开始
--做某事
结尾
吧
开始
--做点别的事
结尾
去
begin
--do something
end
GO
begin
--do something else
end
GO