Code formatting
@dsfog
Posts: 4 Bronze 2
I have noticed som mishaps when auto formatting my code, where perfectly sane TSQL is going off.
Most simple example I have found:
Write
Line is now
Same mishaps are at times found for ASC and DESC keywords, but I have not identified a way to consistently reproduce these errors (nor tried to).
Setup
SSMS 2012
SQL Prompt 5.3.6.28
Connection Coloring as only experimental feature[/code]
Exported Style XML:
<?xml version="1.0" encoding="utf-16" standalone="yes"?>
<!---->
<LayoutOptions version="1" type="LayoutOptions">
<ReservedWordsCasing>1</ReservedWordsCasing>
<BuiltInFunctionCasing>1</BuiltInFunctionCasing>
<BuiltInDataTypeCasing>1</BuiltInDataTypeCasing>
<DelimitIdentifiers>False</DelimitIdentifiers>
<IndentationAmount>4</IndentationAmount>
<UseTabs>False</UseTabs>
<ReformatExpressions>True</ReformatExpressions>
<FirstColumnOnNewLine>False</FirstColumnOnNewLine>
<CommasAtStart>True</CommasAtStart>
<MultilineSpacesAfterCommas>True</MultilineSpacesAfterCommas>
<MultilineSpacesBeforeCommas>True</MultilineSpacesBeforeCommas>
<MultilineAlignCommasWithStatement>False</MultilineAlignCommasWithStatement>
<OperatorsOnNewline>True</OperatorsOnNewline>
<OperatorsAtStart>True</OperatorsAtStart>
<IndentBeginToken>True</IndentBeginToken>
<IndentWithExpressionBrackets>True</IndentWithExpressionBrackets>
<IndentWithParameterBrackets>True</IndentWithParameterBrackets>
<IndentWithQueryBrackets>True</IndentWithQueryBrackets>
<CloseBracketsOnNewLine>True</CloseBracketsOnNewLine>
<OpenBracketsOnNewLine>False</OpenBracketsOnNewLine>
<Wrap>True</Wrap>
<WrapWidth>78</WrapWidth>
<ShortLength>15</ShortLength>
<CreateBracketsAtStartOfLines>False</CreateBracketsAtStartOfLines>
<ParameterBracketOnNewline>True</ParameterBracketOnNewline>
<CloseParameterBracketsOnNewLine>True</CloseParameterBracketsOnNewLine>
<CompactShortStatements>False</CompactShortStatements>
<SinglelineSpacesAfterCommas>True</SinglelineSpacesAfterCommas>
<SinglelineSpacesBeforeCommas>False</SinglelineSpacesBeforeCommas>
<SpacesAroundOperators>True</SpacesAroundOperators>
<SpacesAroundComparisons>True</SpacesAroundComparisons>
<FirstParameterDefinitionOnNewLine>True</FirstParameterDefinitionOnNewLine>
<SpacesAfterBrackets>False</SpacesAfterBrackets>
<LayoutSelectStatements>True</LayoutSelectStatements>
<LayoutCreateStatements>True</LayoutCreateStatements>
<QueryNewlineAfterOpenBracket>False</QueryNewlineAfterOpenBracket>
<QueryNewlineBeforeCloseBracket>True</QueryNewlineBeforeCloseBracket>
<JoinConditionsOnNewline>True</JoinConditionsOnNewline>
<AlignConditionsWithJoins>False</AlignConditionsWithJoins>
<AlignJoinsWithFrom>True</AlignJoinsWithFrom>
<IndentByKeywordWidth>False</IndentByKeywordWidth>
<ColumnsOnSingleLine>False</ColumnsOnSingleLine>
<DoNotIndentProcedureContents>False</DoNotIndentProcedureContents>
<ExecuteParametersOnSingleLine>True</ExecuteParametersOnSingleLine>
<UseSpacesInsteadOfTabs>False</UseSpacesInsteadOfTabs>
<IndentSelectSubclauses>False</IndentSelectSubclauses>
</LayoutOptions>
Most simple example I have found:
Write
DROP TABLEWith caret placed exactly after TABLE press Ctrl + Enter.
Line is now
DROTABLELE
Same mishaps are at times found for ASC and DESC keywords, but I have not identified a way to consistently reproduce these errors (nor tried to).
Setup
SSMS 2012
SQL Prompt 5.3.6.28
Connection Coloring as only experimental feature[/code]
Exported Style XML:
<?xml version="1.0" encoding="utf-16" standalone="yes"?>
<!---->
<LayoutOptions version="1" type="LayoutOptions">
<ReservedWordsCasing>1</ReservedWordsCasing>
<BuiltInFunctionCasing>1</BuiltInFunctionCasing>
<BuiltInDataTypeCasing>1</BuiltInDataTypeCasing>
<DelimitIdentifiers>False</DelimitIdentifiers>
<IndentationAmount>4</IndentationAmount>
<UseTabs>False</UseTabs>
<ReformatExpressions>True</ReformatExpressions>
<FirstColumnOnNewLine>False</FirstColumnOnNewLine>
<CommasAtStart>True</CommasAtStart>
<MultilineSpacesAfterCommas>True</MultilineSpacesAfterCommas>
<MultilineSpacesBeforeCommas>True</MultilineSpacesBeforeCommas>
<MultilineAlignCommasWithStatement>False</MultilineAlignCommasWithStatement>
<OperatorsOnNewline>True</OperatorsOnNewline>
<OperatorsAtStart>True</OperatorsAtStart>
<IndentBeginToken>True</IndentBeginToken>
<IndentWithExpressionBrackets>True</IndentWithExpressionBrackets>
<IndentWithParameterBrackets>True</IndentWithParameterBrackets>
<IndentWithQueryBrackets>True</IndentWithQueryBrackets>
<CloseBracketsOnNewLine>True</CloseBracketsOnNewLine>
<OpenBracketsOnNewLine>False</OpenBracketsOnNewLine>
<Wrap>True</Wrap>
<WrapWidth>78</WrapWidth>
<ShortLength>15</ShortLength>
<CreateBracketsAtStartOfLines>False</CreateBracketsAtStartOfLines>
<ParameterBracketOnNewline>True</ParameterBracketOnNewline>
<CloseParameterBracketsOnNewLine>True</CloseParameterBracketsOnNewLine>
<CompactShortStatements>False</CompactShortStatements>
<SinglelineSpacesAfterCommas>True</SinglelineSpacesAfterCommas>
<SinglelineSpacesBeforeCommas>False</SinglelineSpacesBeforeCommas>
<SpacesAroundOperators>True</SpacesAroundOperators>
<SpacesAroundComparisons>True</SpacesAroundComparisons>
<FirstParameterDefinitionOnNewLine>True</FirstParameterDefinitionOnNewLine>
<SpacesAfterBrackets>False</SpacesAfterBrackets>
<LayoutSelectStatements>True</LayoutSelectStatements>
<LayoutCreateStatements>True</LayoutCreateStatements>
<QueryNewlineAfterOpenBracket>False</QueryNewlineAfterOpenBracket>
<QueryNewlineBeforeCloseBracket>True</QueryNewlineBeforeCloseBracket>
<JoinConditionsOnNewline>True</JoinConditionsOnNewline>
<AlignConditionsWithJoins>False</AlignConditionsWithJoins>
<AlignJoinsWithFrom>True</AlignJoinsWithFrom>
<IndentByKeywordWidth>False</IndentByKeywordWidth>
<ColumnsOnSingleLine>False</ColumnsOnSingleLine>
<DoNotIndentProcedureContents>False</DoNotIndentProcedureContents>
<ExecuteParametersOnSingleLine>True</ExecuteParametersOnSingleLine>
<UseSpacesInsteadOfTabs>False</UseSpacesInsteadOfTabs>
<IndentSelectSubclauses>False</IndentSelectSubclauses>
</LayoutOptions>
Comments
As per the OP, I can't find a certain way to consistently reproduce (although the Ctrl+Enter after DROP TABLE produces the same results), so was assuming it was keyboard clumsiness.
The example I had was 'select * from' then Ctrl+Enter, becomes 'select fromom'
Riley Waterhouse Limited
Twitter: @kevriley
Drop Table Ctrl+space works fine, but I too get the problem with Ctrl+Enter with version 5.3.6.28 in SSMS 2008r2