diff --git a/src/sqlfluff/dialects/dialect_tsql.py b/src/sqlfluff/dialects/dialect_tsql.py index 4e650aa129f..966c66119a0 100644 --- a/src/sqlfluff/dialects/dialect_tsql.py +++ b/src/sqlfluff/dialects/dialect_tsql.py @@ -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" @@ -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", diff --git a/test/fixtures/dialects/tsql/add_index.sql b/test/fixtures/dialects/tsql/add_index.sql index 7e905285600..77bc14899a1 100644 --- a/test/fixtures/dialects/tsql/add_index.sql +++ b/test/fixtures/dialects/tsql/add_index.sql @@ -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 diff --git a/test/fixtures/dialects/tsql/add_index.yml b/test/fixtures/dialects/tsql/add_index.yml index e7bd7dd6cab..4986f0c1d58 100644 --- a/test/fixtures/dialects/tsql/add_index.yml +++ b/test/fixtures/dialects/tsql/add_index.yml @@ -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: @@ -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