ApexSQL Refactor是否提供类似--begin_no_format的无格式化代码块功能?
Great question! I’ve dealt with this exact issue when switching from SQL Pretty Printer to ApexSQL Refactor, so I know how frustrating it can be to miss that handy comment-based exclusion feature.
Unfortunately, ApexSQL Refactor doesn’t have a native equivalent to --begin_no_format/--end_no_format as of its latest version (2024)—I’ve checked the official docs and settings thoroughly too. But there are a few reliable workarounds to get the same result:
Disrupt the formatter with dummy inline comments
ApexSQL’s formatter parses SQL syntax strictly, so adding a harmless, syntax-valid comment that breaks its pattern matching will prevent it from reformatting a block. A common trick is using the MySQL-style/*! */comment (which most SQL engines ignore):-- This block won't be formatted by ApexSQL SELECT FirstName, LastName FROM Customers WHERE /*! */ Country = 'USA' AND /*! */ SignupDate > '2023-01-01'The comments act as "roadblocks" for the formatter, leaving your line breaks and spacing intact.
Format selectively instead of globally
If you’re using ApexSQL with SSMS or Visual Studio, you can avoid formatting unwanted sections by:- Highlighting only the code you do want formatted
- Using the Format Selection option (found in the ApexSQL Refactor menu > Format SQL) instead of formatting the entire file.
- For files you never want touched by the formatter, add them to the "Excluded files" list in ApexSQL’s settings (under Format SQL > General > Excluded files).
Tweak custom formatting rules
If you have a consistent pattern for unformatted code (e.g., wrapped in a specific comment), you can adjust ApexSQL’s formatting rules to preserve that section. For example, you can modify the "Line breaks around comments" rule to keep line breaks inside blocks marked with-- NO_FORMATcomments.
If this workaround feels clunky, I’d suggest submitting a feature request to ApexSQL’s support team—they’ve been known to add user-requested features in updates.
内容的提问来源于stack exchange,提问作者Dayton Brown

