Skip to content

Commit

Permalink
TSQL: CREATE STATISTICS (#1662)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpers36 authored Oct 15, 2021
1 parent 83d2f57 commit ec7c2dd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/sqlfluff/dialects/dialect_tsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,10 @@ class WhereClauseSegment(BaseSegment):

@tsql_dialect.segment(replace=True)
class CreateIndexStatementSegment(BaseSegment):
"""A `CREATE INDEX` statement.
"""A `CREATE INDEX` or `CREATE STATISTICS` statement.
https://docs.microsoft.com/en-us/sql/t-sql/statements/create-index-transact-sql?view=sql-server-ver15
https://docs.microsoft.com/en-us/sql/t-sql/statements/create-statistics-transact-sql?view=sql-server-ver15
"""

type = "create_index_statement"
Expand All @@ -324,7 +325,7 @@ class CreateIndexStatementSegment(BaseSegment):
Ref("OrReplaceGrammar", optional=True),
Sequence("UNIQUE", optional=True),
OneOf("CLUSTERED", "NONCLUSTERED", optional=True),
"INDEX",
OneOf("INDEX", "STATISTICS"),
Ref("IfNotExistsGrammar", optional=True),
Ref("IndexReferenceSegment"),
"ON",
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/dialects/tsql/add_index.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ IF EXISTS(SELECT * FROM sys.indexes WHERE NAME='IX_INTER_VIMR_REPRODUCTION_NUMBE
CREATE CLUSTERED INDEX IX_INTER_VIMR_REPRODUCTION_NUMBER
ON dbo.VIMR_INFECTIOUS_PEOPLE(DATE_LAST_INSERTED);
GO


CREATE STATISTICS Stats_Population ON [Reporting].[Population]
([ID],[Facility],[Population])

GO
27 changes: 26 additions & 1 deletion test/fixtures/dialects/tsql/add_index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# computed by SQLFluff when running the tests. Please run
# `python test/generate_parse_fixture_yml.py` to generate them after adding or
# altering SQL files.
_hash: 2122ec7aca5f6835c66088ad5d48be7e9bda62f0ec75767628621cb82f94e0a9
_hash: 56af05bcacbc11b6e52f53d6f419d3e67b1c3dbceb18e26d52f481c30a2e8f24
file:
- batch:
statement:
Expand Down Expand Up @@ -166,3 +166,28 @@ file:
- statement_terminator: ;
- go_statement:
keyword: GO
- batch:
statement:
create_index_statement:
- keyword: CREATE
- keyword: STATISTICS
- index_reference:
identifier: Stats_Population
- keyword: 'ON'
- table_reference:
- identifier: '[Reporting]'
- dot: .
- identifier: '[Population]'
- bracketed:
- start_bracket: (
- index_column_definition:
identifier: '[ID]'
- comma: ','
- index_column_definition:
identifier: '[Facility]'
- comma: ','
- index_column_definition:
identifier: '[Population]'
- end_bracket: )
- go_statement:
keyword: GO

0 comments on commit ec7c2dd

Please sign in to comment.