일관된 서식을 사용하면 특히 여러 사람이 동일한 코드베이스에 기여하는 경우 T-SQL(Transact-SQL)을 더 쉽게 읽고, 검토하고, 유지 관리할 수 있습니다. Visual Studio Code용 MSSQL 확장 프로그램에는 내장된 SQL 포맷터가 포함되어 있어 주문 시 실행할 수 있고, 저장 시 자동 서식 설정과 Visual Studio Code 설정을 통해 커스터마이즈할 수 있습니다.
MSSQL 확장 기능의 T-SQL 서식 기능은 ScriptDOM이라는 오픈 소스 .NET 라이브러리를 기반으로 구축되어 있으며, 이 라이브러리는 T-SQL을 구싱하고 추상 구문 트리를 기반으로 스크립트를 생성합니다.
필요 시 포맷
어떤 에디터 창에서도 T-SQL을 포맷할 수 있습니다. 포맷터는 문서 전체에 적용되거나 선택한 텍스트에만 적용됩니다.
주문 시 T-SQL을 포맷하려면 다음 방법 중 하나를 사용하세요:
컨텍스트 메뉴: T-SQL 편집기 창에서 오른쪽 클릭으로 문서 형식 또는 형식 선택을 선택하세요.
명령 팔레트: 문서 형식 실행 또는 형식 선택.
키보드 바로가기: 문서 형식은 Windows와 Linux에서 Shift+Alt+F를, macOS에서는 Shift+옵션+F를 누르세요. 포맷 선택은 Windows와 Linux에서는 Ctrl+K, Ctrl+F, macOS에서는 Cmd+K, Cmd+F를 누르세요.
저장할 때 서식 지정
Visual Studio Code에서는 표준 편집기 설정이 저장 시 포맷을 제어하며, 전용 MSSQL 포맷터 설정이 아닙니다.
파일을 저장할 때마다 자동으로 T-SQL을 포맷하려면 Visual Studio Code settings.json 파일에서 다음 설정을 사용하세요:
{
"[sql]": {
"editor.formatOnSave": true
}
}
서식 옵션 구성
Visual Studio Code 설정 UI나 사용자 또는 작업 공간settings.json에서 서식을 설정하세요.
설정 편집기에서 Mssql>형식을 검색하면 사용 가능한 옵션을 볼 수 있습니다.
settings.json에서는 해당 mssql.format.* 설정을 사용하세요.
지원되는 설정
다음 설정들은 SQL 포맷터를 구성합니다.
일반
| Setting | Type | Default | Description |
|---|---|---|---|
mssql.format.showParseErrorNotification |
bool | true |
포맷터가 T-SQL을 완전히 파싱하지 못하면 알림을 보여줘. |
mssql.format.options.sqlVersion |
enum | sql170 |
T-SQL 버전은 구식 스크립트를 파싱하고 생성하는 데 사용되었습니다. |
mssql.format.options.sqlEngineType |
enum | all |
데이터베이스 엔진 타입은 형식화된 스크립트를 구싱하고 생성하는 데 사용됩니다. 유효한 값은 all, standalone 및 sqlAzure입니다. |
정렬
| Setting | Type | Default | Description |
|---|---|---|---|
mssql.format.options.alignClauseBodies |
bool | true |
FROM, WHERE, GROUP BY 및 유사한 절의 본문을 맞춥니다. |
mssql.format.options.alignColumnDefinitionFields |
bool | true |
이름, 데이터 타입, 제약 조건과 같은 열 정의 필드를 정렬합니다. |
mssql.format.options.alignSetClauseItem |
bool | true |
SET 문에서 UPDATE 절 항목을 정렬합니다. |
mssql.format.options.clauseBodyAlignment |
enum | aligned |
절의 본문 aligned은 키워드와 같은 줄에 유지하거나 indented처럼 다음 줄에 배치하세요. |
케이싱 및 식별자
| Setting | Type | Default | Description |
|---|---|---|---|
mssql.format.options.builtInFunctionCasing |
enum | preserve |
지원되는 내장 함수명(예: GETDATECOALESCE)의 케이싱 스타일 유효한 값은 preserve, uppercase, lowercase 및 pascalCase입니다. |
mssql.format.options.identifierBracketing |
enum | preserve |
식별자 주변에 선택적 대괄호를 보존, 추가, 제거하세요. 유효한 값은 preserve, includeBrackets 및 excludeBrackets입니다. 필요한 괄호는 유지됩니다. |
mssql.format.options.identifierCasing |
enum | preserve |
객체 식별자를 위한 케이싱 스타일. 유효한 값은 preserve, uppercase, lowercase 및 pascalCase입니다. |
mssql.format.options.keywordCasing |
enum | uppercase |
키워드 대문자/소문자 스타일 유효한 값은 uppercase, lowercase 및 pascalCase입니다. |
Paths
| Setting | Type | Default | Description |
|---|---|---|---|
mssql.format.options.allowExternalLanguagePaths |
bool | true |
외부 언어 콘텐츠가 파일 경로를 사용할 수 있도록 허용하세요. |
mssql.format.options.allowExternalLibraryPaths |
bool | true |
외부 라이브러리 콘텐츠가 파일 경로를 사용할 수 있도록 허용하세요. |
서식
| Setting | Type | Default | Description |
|---|---|---|---|
mssql.format.options.asKeywordOnOwnLine |
bool | true |
AS를 별도 줄에 배치합니다. |
mssql.format.options.columnAliasStyle |
enum | asKeyword |
AS, 등호 또는 원래 구문을 사용해 열 별칭의 형식을 지정하세요. 유효한 값은 asKeyword, equalsSign 및 preserve입니다. |
mssql.format.options.commaPlacement |
enum | trailing |
목록 항목trailing 끝()이나 다음 항목 시작 부분()에 쉼표를 붙이세요.leading |
mssql.format.options.leadingCommaSpaceCount |
정수 | 1 |
앞 쉼표 뒤의 공백 수. 유효한 값은 0 및 1입니다. |
mssql.format.options.persistTrailingGo |
bool | false |
원본 스크립트 끝에 있는 GO 배치 구분자를 보존하세요. |
mssql.format.options.preserveComments |
bool | true |
서식을 지정하는 동안 주석을 유지합니다. |
mssql.format.options.terminateBlockStatements |
bool | false |
BEGIN...END 및 TRY...CATCH 블록 뒤에 세미콜론 종결자를 추가하세요. |
들여쓰기
| Setting | Type | Default | Description |
|---|---|---|---|
mssql.format.options.indentSetClause |
bool | false |
SET 문에서 UPDATE 절을 들여쓰기합니다. |
mssql.format.options.indentViewBody |
bool | false |
VIEW 본문을 들여쓰세요. |
여러 줄
| Setting | Type | Default | Description |
|---|---|---|---|
mssql.format.options.multilineGroupByElementsList |
bool | false |
요소는 다중 줄 목록으로 포맷하세요 GROUP BY . |
mssql.format.options.multilineHavingPredicatesList |
bool | true |
여러 줄에서 OR 또는 HAVING로 구분된 AND 술어를 형식화합니다. |
mssql.format.options.multilineInsertSourcesList |
bool | true |
소스를 다중 라인 리스트로 포맷하세요 INSERT . |
mssql.format.options.multilineInsertTargetsList |
bool | true |
열을 다중 줄 목록으로 포맷하세요 INSERT . |
mssql.format.options.multilineInValuesList |
bool | false |
IN 술어의 값을 여러 줄 목록 형식으로 지정합니다. |
mssql.format.options.multilineNestedFunctionCalls |
bool | false |
중첩된 함수 호출은 들여쓴 별도 줄에 배치하고, 독립적인 함수 호출은 한 줄에 유지하세요. |
mssql.format.options.multilineOrderByElementsList |
bool | false |
요소는 다중 줄 목록으로 포맷하세요 ORDER BY . |
mssql.format.options.multilinePartitionByElementsList |
bool | false |
창 명세에서 요소들을 다중 줄 목록으로 포맷하세요 PARTITION BY . |
mssql.format.options.multilineProcedureParametersList |
bool | false |
프로시저와 기능 매개변수를 별도의 라인으로 포맷하세요. |
mssql.format.options.multilineSelectElementsList |
bool | true |
열을 다중 줄 목록으로 포맷하세요 SELECT . |
mssql.format.options.multilineSetClauseItems |
bool | true |
SET 절 항목의 서식을 여러 줄 목록으로 지정하세요. |
mssql.format.options.multilineViewColumnsList |
bool | true |
열을 다중 줄 목록으로 포맷하세요 VIEW . |
mssql.format.options.multilineWherePredicatesList |
bool | true |
WHERE 술어의 서식을 여러 줄 목록으로 지정하세요. |
mssql.format.options.multilineWithOptionsList |
bool | false |
지원되는 WITH 형식과 OPTION 절 값은 별도의 줄에 배치되어 있습니다. |
새 줄
| Setting | Type | Default | Description |
|---|---|---|---|
mssql.format.options.newLineAfterJoinKeyword |
bool | true |
조인된 테이블 소스를 JOIN 키워드 뒤의 새 줄에 배치하세요. |
mssql.format.options.newLineBeforeCloseParenthesisInMultilineList |
bool | true |
다중 줄 목록의 닫는 괄호 앞에 새 줄을 넣으세요. |
mssql.format.options.newLineBeforeFromClause |
bool | true |
조항 앞에 새 줄을 넣으세요 FROM . |
mssql.format.options.newLineBeforeGroupByClause |
bool | true |
조항 앞에 새 줄을 넣으세요 GROUP BY . |
mssql.format.options.newLineBeforeHavingClause |
bool | true |
조항 앞에 새 줄을 넣으세요 HAVING . |
mssql.format.options.newLineBeforeJoinClause |
bool | true |
JOIN 절 앞에 새 줄을 넣으세요. |
mssql.format.options.newLineBeforeOffsetClause |
bool | true |
조항 앞에 새 줄을 넣으세요 OFFSET . |
mssql.format.options.newLineBeforeOnClause |
bool | true |
조인의 ON절을 새 줄에 배치하세요. |
mssql.format.options.newLineBeforeOpenParenthesisInMultilineList |
bool | false |
다중 줄 목록의 첫 괄호 앞에 새 줄을 넣으세요. |
mssql.format.options.newLineBeforeOrderByClause |
bool | true |
조항 앞에 새 줄을 넣으세요 ORDER BY . |
mssql.format.options.newLineBeforeOutputClause |
bool | true |
조항 앞에 새 줄을 넣으세요 OUTPUT . |
mssql.format.options.newLineBeforeWhereClause |
bool | true |
조항 앞에 새 줄을 넣으세요 WHERE . |
mssql.format.options.newLineBeforeWindowClause |
bool | true |
조항 앞에 새 줄을 넣으세요 WINDOW . |
mssql.format.options.newlineFormattedCheckConstraint |
bool | false |
제약 조건의 CHECK 절을 별도의 줄에 배치하세요. |
mssql.format.options.newLineFormattedIndexDefinition |
bool | false |
인라인 인덱스 정의의 일부를 별도의 라인에 배치합니다UNIQUEINCLUDEWHERE. |
명설 및 배치 간격
| Setting | Type | Default | Description |
|---|---|---|---|
mssql.format.options.numNewlinesAfterBatches |
정수 | 1 |
0부터 5까지 각 GO 배치 구분자 뒤의 줄 바꿈 수. |
mssql.format.options.numNewlinesAfterBatchStatement |
정수 | 2 |
배치에서 각 최상위 문 뒤의 줄바꿈 수(0부터 5까지). |
mssql.format.options.numNewlinesAfterStatement |
정수 | 1 |
각 문 뒤의 줄 바꿈 수, 0부터 5까지. |
Spacing
| Setting | Type | Default | Description |
|---|---|---|---|
mssql.format.options.spaceBetweenDataTypeAndParameters |
bool | true |
예를 VARCHAR (255)들어, 데이터 타입과 괄호 사이에 공백을 삽입하세요. |
mssql.format.options.spaceBetweenParametersInDataType |
bool | true |
예를 DECIMAL (10, 2)들어, 데이터 타입에서 매개변수 사이에 공백을 삽입합니다. |
예시 설정 파일
{
"mssql.format.options.keywordCasing": "lowercase",
"mssql.format.options.alignClauseBodies": false,
"mssql.format.options.numNewlinesAfterStatement": 2,
"[sql]": {
"editor.formatOnSave": true
}
}
기본 포맷터 설정하세요
MSSQL 확장을 기본값으로 설정하려면 '기본 포매터 구성 설정'을 선택하세요...>SQL Server (mssql)를 추가하거나 다음 구성을 추가할 settings.json수 있습니다:
{
"[sql]": {
"editor.defaultFormatter": "ms-mssql.mssql"
}
}