sql 服务器 #region

发布于 2024-10-06 18:15:34 字数 89 浏览 2 评论 0原文

我可以在 sql server 编辑器中创建区域(如 C# 中的 #region#endregion)吗?

Can I create regions in sql server editor (like #region and #endregion in C#) ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

梦罢 2024-10-13 18:15:34

不是真的,抱歉!但是...

添加 beginend.. 在 begin 上添加注释会创建如下所示的区域...不过有点黑客行为!

start end 区域代码的屏幕截图

否则你只能展开和折叠你就可以' t 规定应该展开和折叠的内容。离不开第三方工具,例如 SSMS 工具包

Not really, Sorry! But...

Adding begin and end.. with a comment on the begin creates regions which would look like this...bit of hack though!

screenshot of begin end region code

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.

∞梦里开花 2024-10-13 18:15:34

(我是 SSMS 的 SSMSBoost 插件的开发人员)

我们最近在 SSMSBoost 插件中添加了对此语法的支持 -在。

--#region [Optional Name]
--#endregion

它还具有在打开脚本时自动“识别”区域的选项。

(I am developer of SSMSBoost add-in for SSMS)

We have recently added support for this syntax into our SSMSBoost add-in.

--#region [Optional Name]
--#endregion

It has also an option to automatically "recognize" regions when opening scripts.

花桑 2024-10-13 18:15:34

BEGIN...END 有效,您只需添加注释部分即可。最简单的方法是添加部分名称!另一种途径是添加评论块。见下文:

BEGIN  -- Section Name
/* 
Comment block some stuff  --end comment should be on next line
*/

 --Very long query
SELECT * FROM FOO
SELECT * FROM BAR
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:

BEGIN  -- Section Name
/* 
Comment block some stuff  --end comment should be on next line
*/

 --Very long query
SELECT * FROM FOO
SELECT * FROM BAR
END
迷离° 2024-10-13 18:15:34

这只是在查询编辑器中使用文本缩进的问题。

扩展视图:

展开

折叠视图:

< img src="https://i.sstatic.net/kQi6O.jpg" alt="折叠">

It is just a matter of using text indentation in the query editor.

Expanded View:

Expanded

Collapsed View:

Collapsed

尛丟丟 2024-10-13 18:15:34

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

一场信仰旅途 2024-10-13 18:15:34

不,T-SQL 语言中不存在#region。

您可以使用 begin-end 块进行代码折叠:

-- my region
begin
    -- code goes here
end

我不确定我是否会建议使用它们,除非代码不能通过其他方式进行可接受的重构!

No, #region does not exist in the T-SQL language.

You can get code-folding using begin-end blocks:

-- my region
begin
    -- code goes here
end

I'm not sure I'd recommend using them for this unless the code cannot be acceptably refactored by other means though!

夜深人未静 2024-10-13 18:15:34

我使用了类似于 McVitie 的技术,并且仅在相当长的存储过程或脚本中使用。我将像这样分解某些功能部分:

BEGIN /** delete queries **/

DELETE FROM blah_blah

END /** delete queries **/

BEGIN /** update queries **/

UPDATE sometable SET something = 1

END /** update queries **/

此方法在管理工作室中显示得相当好,并且对于审查代码非常有帮助。折叠的部分看起来有点像:

BEGIN /** delete queries **/ ... /** delete queries **/

我实际上更喜欢这种方式,因为我知道我的 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:

BEGIN /** delete queries **/

DELETE FROM blah_blah

END /** delete queries **/

BEGIN /** update queries **/

UPDATE sometable SET something = 1

END /** update queries **/

This method shows up fairly nice in management studio and is really helpful in reviewing code. The collapsed piece looks sort of like:

BEGIN /** delete queries **/ ... /** delete queries **/

I actually prefer it this way because I know that my BEGIN matches with the END this way.

桃扇骨 2024-10-13 18:15:34

另一种选择是,

如果您的目的是分析查询,Notepad+ 具有有用的 Sql 自动包装器。

Another option is

if your purpose is analyse your query, Notepad+ has useful automatic wrapper for Sql.

乱世争霸 2024-10-13 18:15:34

如果您不想向 SSMS 添加插件,您可以这样做并获取可折叠和可展开的代码块

BEGIN --#region [DisplayDate]
    
    SELECT GETDATE() CurrentDate

END   --#endregion

在 SQL 代码部分中使用区域

在 SQL 代码部分中使用区域 - 折叠部分

您不必添加 #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

BEGIN --#region [DisplayDate]
    
    SELECT GETDATE() CurrentDate

END   --#endregion

Using regions in SQL code sections

Using regions in SQL code sections - collapsed section

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

忘年祭陌 2024-10-13 18:15:34

开始
--做某事
结尾

开始
--做点别的事
结尾

begin
--do something
end
GO

begin
--do something else
end
GO

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文