-
Notifications
You must be signed in to change notification settings - Fork 5
/
TSqlParser.g4
6102 lines (5443 loc) · 204 KB
/
TSqlParser.g4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
T-SQL (Transact-SQL, MSSQL) grammar.
The MIT License (MIT).
Copyright (c) 2017, Mark Adams (madams51703@gmail.com)
Copyright (c) 2015-2017, Ivan Kochurkin (kvanttt@gmail.com), Positive Technologies.
Copyright (c) 2016, Scott Ure (scott@redstormsoftware.com).
Copyright (c) 2016, Rui Zhang (ruizhang.ccs@gmail.com).
Copyright (c) 2016, Marcus Henriksson (kuseman80@gmail.com).
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
parser grammar TSqlParser;
options { tokenVocab=TSqlLexer; }
tsql_file
: go_statement* EOF
| batch_without_go (go_statement batch_without_go?)* go_statement? EOF
;
batch_without_go
: sql_clauses+
| batch_level_statement
| execute_body_batch sql_clauses*
;
batch_level_statement
: create_or_alter_function
| create_or_alter_procedure
| create_or_alter_trigger
| create_view
;
sql_clauses
: dml_clause SEMI?
| cfl_statement SEMI?
| another_statement SEMI?
| ddl_clause SEMI?
| dbcc_clause SEMI?
| backup_statement SEMI?
| SEMI
;
// Data Manipulation Language: https://msdn.microsoft.com/en-us/library/ff848766(v=sql.120).aspx
dml_clause
: merge_statement
| delete_statement
| insert_statement
| select_statement_standalone
| update_statement
;
// Data Definition Language: https://msdn.microsoft.com/en-us/library/ff848799.aspx)
ddl_clause
: alter_application_role
| alter_assembly
| alter_asymmetric_key
| alter_authorization
| alter_authorization_for_azure_dw
| alter_authorization_for_parallel_dw
| alter_authorization_for_sql_database
| alter_availability_group
| alter_certificate
| alter_column_encryption_key
| alter_credential
| alter_cryptographic_provider
| alter_database
| alter_database_audit_specification
| alter_db_role
| alter_endpoint
| alter_external_data_source
| alter_external_library
| alter_external_resource_pool
| alter_fulltext_catalog
| alter_fulltext_stoplist
| alter_index
| alter_login_azure_sql
| alter_login_azure_sql_dw_and_pdw
| alter_login_sql_server
| alter_master_key_azure_sql
| alter_master_key_sql_server
| alter_message_type
| alter_partition_function
| alter_partition_scheme
| alter_remote_service_binding
| alter_resource_governor
| alter_schema_azure_sql_dw_and_pdw
| alter_schema_sql
| alter_sequence
| alter_server_audit
| alter_server_audit_specification
| alter_server_configuration
| alter_server_role
| alter_server_role_pdw
| alter_service
| alter_service_master_key
| alter_symmetric_key
| alter_table
| alter_user
| alter_user_azure_sql
| alter_workload_group
| alter_xml_schema_collection
| create_application_role
| create_assembly
| create_asymmetric_key
| create_column_encryption_key
| create_column_master_key
| create_columnstore_index
| create_credential
| create_cryptographic_provider
| create_database
| create_database_audit_specification
| create_db_role
| create_endpoint
| create_event_notification
| create_external_library
| create_external_resource_pool
| create_fulltext_catalog
| create_fulltext_stoplist
| create_index
| create_login_azure_sql
| create_login_pdw
| create_login_sql_server
| create_master_key_azure_sql
| create_master_key_sql_server
| create_nonclustered_columnstore_index
| create_or_alter_broker_priority
| create_or_alter_event_session
| create_partition_function
| create_partition_scheme
| create_remote_service_binding
| create_resource_pool
| create_route
| create_rule
| create_schema
| create_schema_azure_sql_dw_and_pdw
| create_search_property_list
| create_security_policy
| create_sequence
| create_server_audit
| create_server_audit_specification
| create_server_role
| create_service
| create_statistics
| create_synonym
| create_table
| create_type
| create_user
| create_user_azure_sql_dw
| create_workload_group
| create_xml_index
| create_xml_schema_collection
| disable_trigger
| drop_aggregate
| drop_application_role
| drop_assembly
| drop_asymmetric_key
| drop_availability_group
| drop_broker_priority
| drop_certificate
| drop_column_encryption_key
| drop_column_master_key
| drop_contract
| drop_credential
| drop_cryptograhic_provider
| drop_database
| drop_database_audit_specification
| drop_database_encryption_key
| drop_database_scoped_credential
| drop_db_role
| drop_default
| drop_endpoint
| drop_event_notifications
| drop_event_session
| drop_external_data_source
| drop_external_file_format
| drop_external_library
| drop_external_resource_pool
| drop_external_table
| drop_fulltext_catalog
| drop_fulltext_index
| drop_fulltext_stoplist
| drop_function
| drop_index
| drop_login
| drop_master_key
| drop_message_type
| drop_partition_function
| drop_partition_scheme
| drop_procedure
| drop_queue
| drop_remote_service_binding
| drop_resource_pool
| drop_route
| drop_rule
| drop_schema
| drop_search_property_list
| drop_security_policy
| drop_sequence
| drop_server_audit
| drop_server_audit_specification
| drop_server_role
| drop_service
| drop_signature
| drop_statistics
| drop_statistics_name_azure_dw_and_pdw
| drop_symmetric_key
| drop_synonym
| drop_table
| drop_trigger
| drop_type
| drop_user
| drop_view
| drop_workload_group
| drop_xml_schema_collection
| enable_trigger
| lock_table
| truncate_table
| update_statistics
;
backup_statement
: backup_database
| backup_log
| backup_certificate
| backup_master_key
| backup_service_master_key
;
// Control-of-Flow Language: https://docs.microsoft.com/en-us/sql/t-sql/language-elements/control-of-flow
cfl_statement
: block_statement
| break_statement
| continue_statement
| goto_statement
| if_statement
| print_statement
| raiseerror_statement
| return_statement
| throw_statement
| try_catch_statement
| waitfor_statement
| while_statement
;
// https://docs.microsoft.com/en-us/sql/t-sql/language-elements/begin-end-transact-sql
block_statement
: BEGIN ';'? sql_clauses* END ';'?
;
// https://docs.microsoft.com/en-us/sql/t-sql/language-elements/break-transact-sql
break_statement
: BREAK ';'?
;
// https://docs.microsoft.com/en-us/sql/t-sql/language-elements/continue-transact-sql
continue_statement
: CONTINUE ';'?
;
// https://docs.microsoft.com/en-us/sql/t-sql/language-elements/goto-transact-sql
goto_statement
: GOTO id_ ';'?
| id_ ':' ';'?
;
// https://docs.microsoft.com/en-us/sql/t-sql/language-elements/return-transact-sql
return_statement
: RETURN expression? ';'?
;
// https://docs.microsoft.com/en-us/sql/t-sql/language-elements/if-else-transact-sql
if_statement
: IF search_condition sql_clauses (ELSE sql_clauses)? ';'?
;
// https://docs.microsoft.com/en-us/sql/t-sql/language-elements/throw-transact-sql
throw_statement
: THROW (throw_error_number ',' throw_message ',' throw_state)? ';'?
;
throw_error_number
: DECIMAL | LOCAL_ID
;
throw_message
: STRING | LOCAL_ID
;
throw_state
: DECIMAL | LOCAL_ID
;
// https://docs.microsoft.com/en-us/sql/t-sql/language-elements/try-catch-transact-sql
try_catch_statement
: BEGIN TRY ';'? try_clauses=sql_clauses+ END TRY ';'? BEGIN CATCH ';'? catch_clauses=sql_clauses* END CATCH ';'?
;
// https://docs.microsoft.com/en-us/sql/t-sql/language-elements/waitfor-transact-sql
waitfor_statement
: WAITFOR receive_statement? ','? ((DELAY | TIME | TIMEOUT) time)? expression? ';'?
;
// https://docs.microsoft.com/en-us/sql/t-sql/language-elements/while-transact-sql
while_statement
: WHILE search_condition (sql_clauses | BREAK ';'? | CONTINUE ';'?)
;
// https://docs.microsoft.com/en-us/sql/t-sql/language-elements/print-transact-sql
print_statement
: PRINT (expression | DOUBLE_QUOTE_ID) (',' LOCAL_ID)* ';'?
;
// https://docs.microsoft.com/en-us/sql/t-sql/language-elements/raiserror-transact-sql
raiseerror_statement
: RAISERROR '(' msg=(DECIMAL | STRING | LOCAL_ID) ',' severity=constant_LOCAL_ID ','
state=constant_LOCAL_ID (',' (constant_LOCAL_ID | NULL_))* ')' (WITH (LOG | SETERROR | NOWAIT))? ';'?
| RAISERROR DECIMAL formatstring=(STRING | LOCAL_ID | DOUBLE_QUOTE_ID) (',' argument=(DECIMAL | STRING | LOCAL_ID))*
;
empty_statement
: ';'
;
another_statement
: alter_queue
| checkpoint_statement
| conversation_statement
| create_contract
| create_queue
| cursor_statement
| declare_statement
| execute_statement
| kill_statement
| message_statement
| reconfigure_statement
| security_statement
| set_statement
| setuser_statement
| shutdown_statement
| transaction_statement
| use_statement
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/alter-application-role-transact-sql
alter_application_role
: ALTER APPLICATION ROLE appliction_role=id_ WITH (COMMA? NAME EQUAL new_application_role_name=id_)? (COMMA? PASSWORD EQUAL application_role_password=STRING)? (COMMA? DEFAULT_SCHEMA EQUAL app_role_default_schema=id_)?
;
// https://learn.microsoft.com/en-us/sql/t-sql/statements/alter-xml-schema-collection-transact-sql?view=sql-server-ver16
alter_xml_schema_collection
: ALTER XML SCHEMA COLLECTION (id_ '.')? id_ ADD STRING
;
create_application_role
: CREATE APPLICATION ROLE appliction_role=id_ WITH (COMMA? PASSWORD EQUAL application_role_password=STRING)? (COMMA? DEFAULT_SCHEMA EQUAL app_role_default_schema=id_)?
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-aggregate-transact-sql
drop_aggregate
: DROP AGGREGATE ( IF EXISTS )? ( schema_name=id_ DOT )? aggregate_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-application-role-transact-sql
drop_application_role
: DROP APPLICATION ROLE rolename=id_
;
alter_assembly
: alter_assembly_start assembly_name=id_ alter_assembly_clause
;
alter_assembly_start
: ALTER ASSEMBLY
;
alter_assembly_clause
: alter_assembly_from_clause? alter_assembly_with_clause? alter_assembly_drop_clause? alter_assembly_add_clause?
;
alter_assembly_from_clause
: alter_assembly_from_clause_start (client_assembly_specifier | alter_assembly_file_bits )
;
alter_assembly_from_clause_start
: FROM
;
alter_assembly_drop_clause
: alter_assembly_drop alter_assembly_drop_multiple_files
;
alter_assembly_drop_multiple_files
: ALL
| multiple_local_files
;
alter_assembly_drop
: DROP
;
alter_assembly_add_clause
: alter_asssembly_add_clause_start alter_assembly_client_file_clause
;
alter_asssembly_add_clause_start
: ADD FILE FROM
;
// need to implement
alter_assembly_client_file_clause
: alter_assembly_file_name (alter_assembly_as id_)?
;
alter_assembly_file_name
: STRING
;
//need to implement
alter_assembly_file_bits
: alter_assembly_as id_
;
alter_assembly_as
: AS
;
alter_assembly_with_clause
: alter_assembly_with assembly_option
;
alter_assembly_with
: WITH
;
client_assembly_specifier
: network_file_share
| local_file
| STRING
;
assembly_option
: PERMISSION_SET EQUAL (SAFE|EXTERNAL_ACCESS|UNSAFE)
| VISIBILITY EQUAL on_off
| UNCHECKED DATA
| assembly_option COMMA
;
network_file_share
: network_file_start network_computer file_path
;
network_computer
: computer_name=id_
;
network_file_start
: DOUBLE_BACK_SLASH
;
file_path
: file_directory_path_separator file_path
| id_
;
file_directory_path_separator
: '\\'
;
local_file
: local_drive file_path
;
local_drive
:
DISK_DRIVE
;
multiple_local_files
:
multiple_local_file_start local_file SINGLE_QUOTE COMMA
| local_file
;
multiple_local_file_start
: SINGLE_QUOTE
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/create-assembly-transact-sql
create_assembly
: CREATE ASSEMBLY assembly_name=id_ (AUTHORIZATION owner_name=id_)?
FROM (COMMA? (STRING|BINARY) )+
(WITH PERMISSION_SET EQUAL (SAFE|EXTERNAL_ACCESS|UNSAFE) )?
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-assembly-transact-sql
drop_assembly
: DROP ASSEMBLY ( IF EXISTS )? (COMMA? assembly_name=id_)+
( WITH NO DEPENDENTS )?
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/alter-asymmetric-key-transact-sql
alter_asymmetric_key
: alter_asymmetric_key_start Asym_Key_Name=id_ (asymmetric_key_option | REMOVE PRIVATE KEY )
;
alter_asymmetric_key_start
: ALTER ASYMMETRIC KEY
;
asymmetric_key_option
: asymmetric_key_option_start asymmetric_key_password_change_option ( COMMA asymmetric_key_password_change_option)? RR_BRACKET
;
asymmetric_key_option_start
: WITH PRIVATE KEY LR_BRACKET
;
asymmetric_key_password_change_option
: DECRYPTION BY PASSWORD EQUAL STRING
| ENCRYPTION BY PASSWORD EQUAL STRING
;
//https://docs.microsoft.com/en-us/sql/t-sql/statements/create-asymmetric-key-transact-sql
create_asymmetric_key
: CREATE ASYMMETRIC KEY Asym_Key_Nam=id_
(AUTHORIZATION database_principal_name=id_)?
( FROM (FILE EQUAL STRING |EXECUTABLE_FILE EQUAL STRING|ASSEMBLY Assembly_Name=id_ | PROVIDER Provider_Name=id_) )?
(WITH (ALGORITHM EQUAL ( RSA_4096 | RSA_3072 | RSA_2048 | RSA_1024 | RSA_512) |PROVIDER_KEY_NAME EQUAL provider_key_name=STRING | CREATION_DISPOSITION EQUAL (CREATE_NEW|OPEN_EXISTING) ) )?
(ENCRYPTION BY PASSWORD EQUAL asymmetric_key_password=STRING )?
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-asymmetric-key-transact-sql
drop_asymmetric_key
: DROP ASYMMETRIC KEY key_name=id_ ( REMOVE PROVIDER KEY )?
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/alter-authorization-transact-sql
alter_authorization
: alter_authorization_start (class_type colon_colon)? entity=entity_name entity_to authorization_grantee
;
authorization_grantee
: principal_name=id_
| SCHEMA OWNER
;
entity_to
: TO
;
colon_colon
: DOUBLE_COLON
;
alter_authorization_start
: ALTER AUTHORIZATION ON
;
alter_authorization_for_sql_database
: alter_authorization_start (class_type_for_sql_database colon_colon)? entity=entity_name entity_to authorization_grantee
;
alter_authorization_for_azure_dw
: alter_authorization_start (class_type_for_azure_dw colon_colon)? entity=entity_name_for_azure_dw entity_to authorization_grantee
;
alter_authorization_for_parallel_dw
: alter_authorization_start (class_type_for_parallel_dw colon_colon)? entity=entity_name_for_parallel_dw entity_to authorization_grantee
;
class_type
: OBJECT
| ASSEMBLY
| ASYMMETRIC KEY
| AVAILABILITY GROUP
| CERTIFICATE
| CONTRACT
| TYPE
| DATABASE
| ENDPOINT
| FULLTEXT CATALOG
| FULLTEXT STOPLIST
| MESSAGE TYPE
| REMOTE SERVICE BINDING
| ROLE
| ROUTE
| SCHEMA
| SEARCH PROPERTY LIST
| SERVER ROLE
| SERVICE
| SYMMETRIC KEY
| XML SCHEMA COLLECTION
;
class_type_for_sql_database
: OBJECT
| ASSEMBLY
| ASYMMETRIC KEY
| CERTIFICATE
| TYPE
| DATABASE
| FULLTEXT CATALOG
| FULLTEXT STOPLIST
| ROLE
| SCHEMA
| SEARCH PROPERTY LIST
| SYMMETRIC KEY
| XML SCHEMA COLLECTION
;
class_type_for_azure_dw
: SCHEMA
| OBJECT
;
class_type_for_parallel_dw
: DATABASE
| SCHEMA
| OBJECT
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/grant-transact-sql?view=sql-server-ver15
// SELECT DISTINCT '| ' + CLASS_DESC
// FROM sys.dm_audit_actions
// ORDER BY 1
class_type_for_grant
: APPLICATION ROLE
| ASSEMBLY
| ASYMMETRIC KEY
| AUDIT
| AVAILABILITY GROUP
| BROKER PRIORITY
| CERTIFICATE
| COLUMN ( ENCRYPTION | MASTER ) KEY
| CONTRACT
| CREDENTIAL
| CRYPTOGRAPHIC PROVIDER
| DATABASE ( AUDIT SPECIFICATION
| ENCRYPTION KEY
| EVENT SESSION
| SCOPED ( CONFIGURATION
| CREDENTIAL
| RESOURCE GOVERNOR )
)?
| ENDPOINT
| EVENT SESSION
| NOTIFICATION (DATABASE | OBJECT | SERVER)
| EXTERNAL ( DATA SOURCE
| FILE FORMAT
| LIBRARY
| RESOURCE POOL
| TABLE
| CATALOG
| STOPLIST
)
| LOGIN
| MASTER KEY
| MESSAGE TYPE
| OBJECT
| PARTITION ( FUNCTION | SCHEME)
| REMOTE SERVICE BINDING
| RESOURCE GOVERNOR
| ROLE
| ROUTE
| SCHEMA
| SEARCH PROPERTY LIST
| SERVER ( ( AUDIT SPECIFICATION? ) | ROLE )?
| SERVICE
| SQL LOGIN
| SYMMETRIC KEY
| TRIGGER ( DATABASE | SERVER)
| TYPE
| USER
| XML SCHEMA COLLECTION
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-availability-group-transact-sql
drop_availability_group
: DROP AVAILABILITY GROUP group_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/alter-availability-group-transact-sql
alter_availability_group
: alter_availability_group_start alter_availability_group_options
;
alter_availability_group_start
: ALTER AVAILABILITY GROUP group_name=id_
;
alter_availability_group_options
: SET LR_BRACKET ( ( AUTOMATED_BACKUP_PREFERENCE EQUAL ( PRIMARY | SECONDARY_ONLY| SECONDARY | NONE ) | FAILURE_CONDITION_LEVEL EQUAL DECIMAL | HEALTH_CHECK_TIMEOUT EQUAL milliseconds=DECIMAL | DB_FAILOVER EQUAL ( ON | OFF ) | REQUIRED_SYNCHRONIZED_SECONDARIES_TO_COMMIT EQUAL DECIMAL ) RR_BRACKET )
| ADD DATABASE database_name=id_
| REMOVE DATABASE database_name=id_
| ADD REPLICA ON server_instance=STRING (WITH LR_BRACKET ( (ENDPOINT_URL EQUAL STRING)? (COMMA? AVAILABILITY_MODE EQUAL (SYNCHRONOUS_COMMIT| ASYNCHRONOUS_COMMIT))? (COMMA? FAILOVER_MODE EQUAL (AUTOMATIC|MANUAL) )? (COMMA? SEEDING_MODE EQUAL (AUTOMATIC|MANUAL) )? (COMMA? BACKUP_PRIORITY EQUAL DECIMAL)? ( COMMA? PRIMARY_ROLE LR_BRACKET ALLOW_CONNECTIONS EQUAL ( READ_WRITE | ALL ) RR_BRACKET)? ( COMMA? SECONDARY_ROLE LR_BRACKET ALLOW_CONNECTIONS EQUAL ( READ_ONLY ) RR_BRACKET )? )
) RR_BRACKET
|SECONDARY_ROLE LR_BRACKET (ALLOW_CONNECTIONS EQUAL (NO|READ_ONLY|ALL) | READ_ONLY_ROUTING_LIST EQUAL ( LR_BRACKET ( ( STRING) ) RR_BRACKET ) )
|PRIMARY_ROLE LR_BRACKET (ALLOW_CONNECTIONS EQUAL (NO|READ_ONLY|ALL) | READ_ONLY_ROUTING_LIST EQUAL ( LR_BRACKET ( (COMMA? STRING)*|NONE ) RR_BRACKET )
| SESSION_TIMEOUT EQUAL session_timeout=DECIMAL
)
| MODIFY REPLICA ON server_instance=STRING (WITH LR_BRACKET (ENDPOINT_URL EQUAL STRING| AVAILABILITY_MODE EQUAL (SYNCHRONOUS_COMMIT| ASYNCHRONOUS_COMMIT) | FAILOVER_MODE EQUAL (AUTOMATIC|MANUAL) | SEEDING_MODE EQUAL (AUTOMATIC|MANUAL) | BACKUP_PRIORITY EQUAL DECIMAL )
|SECONDARY_ROLE LR_BRACKET (ALLOW_CONNECTIONS EQUAL (NO|READ_ONLY|ALL) | READ_ONLY_ROUTING_LIST EQUAL ( LR_BRACKET ( ( STRING) ) RR_BRACKET ) )
|PRIMARY_ROLE LR_BRACKET (ALLOW_CONNECTIONS EQUAL (NO|READ_ONLY|ALL) | READ_ONLY_ROUTING_LIST EQUAL ( LR_BRACKET ( (COMMA? STRING)*|NONE ) RR_BRACKET )
| SESSION_TIMEOUT EQUAL session_timeout=DECIMAL
) ) RR_BRACKET
| REMOVE REPLICA ON STRING
| JOIN
| JOIN AVAILABILITY GROUP ON (COMMA? ag_name=STRING WITH LR_BRACKET ( LISTENER_URL EQUAL STRING COMMA AVAILABILITY_MODE EQUAL (SYNCHRONOUS_COMMIT|ASYNCHRONOUS_COMMIT) COMMA FAILOVER_MODE EQUAL MANUAL COMMA SEEDING_MODE EQUAL (AUTOMATIC|MANUAL) RR_BRACKET ) )+
| MODIFY AVAILABILITY GROUP ON (COMMA? ag_name_modified=STRING WITH LR_BRACKET (LISTENER_URL EQUAL STRING (COMMA? AVAILABILITY_MODE EQUAL (SYNCHRONOUS_COMMIT|ASYNCHRONOUS_COMMIT) )? (COMMA? FAILOVER_MODE EQUAL MANUAL )? (COMMA? SEEDING_MODE EQUAL (AUTOMATIC|MANUAL))? RR_BRACKET ) )+
|GRANT CREATE ANY DATABASE
| DENY CREATE ANY DATABASE
| FAILOVER
| FORCE_FAILOVER_ALLOW_DATA_LOSS
| ADD LISTENER listener_name=STRING LR_BRACKET ( WITH DHCP (ON LR_BRACKET ip_v4_failover ip_v4_failover RR_BRACKET ) | WITH IP LR_BRACKET ( (COMMA? LR_BRACKET ( ip_v4_failover COMMA ip_v4_failover | ip_v6_failover ) RR_BRACKET)+ RR_BRACKET (COMMA PORT EQUAL DECIMAL)? ) ) RR_BRACKET
| MODIFY LISTENER (ADD IP LR_BRACKET (ip_v4_failover ip_v4_failover | ip_v6_failover) RR_BRACKET | PORT EQUAL DECIMAL )
|RESTART LISTENER STRING
|REMOVE LISTENER STRING
|OFFLINE
| WITH LR_BRACKET DTC_SUPPORT EQUAL PER_DB RR_BRACKET
;
ip_v4_failover
: STRING
;
ip_v6_failover
: STRING
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/alter-broker-priority-transact-sql
// https://docs.microsoft.com/en-us/sql/t-sql/statements/create-broker-priority-transact-sql
create_or_alter_broker_priority
: (CREATE | ALTER) BROKER PRIORITY ConversationPriorityName=id_ FOR CONVERSATION
SET LR_BRACKET
( CONTRACT_NAME EQUAL ( ( id_) | ANY ) COMMA? )?
( LOCAL_SERVICE_NAME EQUAL (DOUBLE_FORWARD_SLASH? id_ | ANY ) COMMA? )?
( REMOTE_SERVICE_NAME EQUAL (RemoteServiceName=STRING | ANY ) COMMA? )?
( PRIORITY_LEVEL EQUAL ( PriorityValue=DECIMAL | DEFAULT ) ) ?
RR_BRACKET
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-broker-priority-transact-sql
drop_broker_priority
: DROP BROKER PRIORITY ConversationPriorityName=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/alter-certificate-transact-sql
alter_certificate
: ALTER CERTIFICATE certificate_name=id_ (REMOVE PRIVATE_KEY | WITH PRIVATE KEY LR_BRACKET ( FILE EQUAL STRING COMMA? | DECRYPTION BY PASSWORD EQUAL STRING COMMA?| ENCRYPTION BY PASSWORD EQUAL STRING COMMA?)+ RR_BRACKET | WITH ACTIVE FOR BEGIN_DIALOG EQUAL ( ON | OFF ) )
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/alter-column-encryption-key-transact-sql
alter_column_encryption_key
: ALTER COLUMN ENCRYPTION KEY column_encryption_key=id_ (ADD | DROP) VALUE LR_BRACKET COLUMN_MASTER_KEY EQUAL column_master_key_name=id_ ( COMMA ALGORITHM EQUAL algorithm_name=STRING COMMA ENCRYPTED_VALUE EQUAL BINARY)? RR_BRACKET
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/create-column-encryption-key-transact-sql
create_column_encryption_key
: CREATE COLUMN ENCRYPTION KEY column_encryption_key=id_
WITH VALUES
(LR_BRACKET COMMA? COLUMN_MASTER_KEY EQUAL column_master_key_name=id_ COMMA
ALGORITHM EQUAL algorithm_name=STRING COMMA
ENCRYPTED_VALUE EQUAL encrypted_value=BINARY RR_BRACKET COMMA?)+
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-certificate-transact-sql
drop_certificate
: DROP CERTIFICATE certificate_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-column-encryption-key-transact-sql
drop_column_encryption_key
: DROP COLUMN ENCRYPTION KEY key_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-column-master-key-transact-sql
drop_column_master_key
: DROP COLUMN MASTER KEY key_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-contract-transact-sql
drop_contract
: DROP CONTRACT dropped_contract_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-credential-transact-sql
drop_credential
: DROP CREDENTIAL credential_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-cryptographic-provider-transact-sql
drop_cryptograhic_provider
: DROP CRYPTOGRAPHIC PROVIDER provider_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-database-transact-sql
drop_database
: DROP DATABASE ( IF EXISTS )? (COMMA? database_name_or_database_snapshot_name=id_)+
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-database-audit-specification-transact-sql
drop_database_audit_specification
: DROP DATABASE AUDIT SPECIFICATION audit_specification_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-database-encryption-key-transact-sql?view=sql-server-ver15
drop_database_encryption_key
: DROP DATABASE ENCRYPTION KEY
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-database-scoped-credential-transact-sql
drop_database_scoped_credential
: DROP DATABASE SCOPED CREDENTIAL credential_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-default-transact-sql
drop_default
: DROP DEFAULT ( IF EXISTS )? (COMMA? (schema_name=id_ DOT)? default_name=id_)
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-endpoint-transact-sql
drop_endpoint
: DROP ENDPOINT endPointName=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-external-data-source-transact-sql
drop_external_data_source
: DROP EXTERNAL DATA SOURCE external_data_source_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-external-file-format-transact-sql
drop_external_file_format
: DROP EXTERNAL FILE FORMAT external_file_format_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-external-library-transact-sql
drop_external_library
: DROP EXTERNAL LIBRARY library_name=id_
( AUTHORIZATION owner_name=id_ )?
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-external-resource-pool-transact-sql
drop_external_resource_pool
: DROP EXTERNAL RESOURCE POOL pool_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-external-table-transact-sql
drop_external_table
: DROP EXTERNAL TABLE (database_name=id_ DOT)? (schema_name=id_ DOT)? table=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-event-notification-transact-sql
drop_event_notifications
: DROP EVENT NOTIFICATION (COMMA? notification_name=id_)+
ON (SERVER|DATABASE|QUEUE queue_name=id_)
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-event-session-transact-sql
drop_event_session
: DROP EVENT SESSION event_session_name=id_
ON SERVER
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-fulltext-catalog-transact-sql
drop_fulltext_catalog
: DROP FULLTEXT CATALOG catalog_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-fulltext-index-transact-sql
drop_fulltext_index
: DROP FULLTEXT INDEX ON (schema=id_ DOT)? table=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-fulltext-stoplist-transact-sql
drop_fulltext_stoplist
: DROP FULLTEXT STOPLIST stoplist_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-login-transact-sql
drop_login
: DROP LOGIN login_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-master-key-transact-sql
drop_master_key
: DROP MASTER KEY
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-message-type-transact-sql
drop_message_type
: DROP MESSAGE TYPE message_type_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-partition-function-transact-sql
drop_partition_function
: DROP PARTITION FUNCTION partition_function_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-partition-scheme-transact-sql
drop_partition_scheme
: DROP PARTITION SCHEME partition_scheme_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-queue-transact-sql
drop_queue
: DROP QUEUE (database_name=id_ DOT)? (schema_name=id_ DOT)? queue_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-remote-service-binding-transact-sql
drop_remote_service_binding
: DROP REMOTE SERVICE BINDING binding_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-resource-pool-transact-sql
drop_resource_pool
: DROP RESOURCE POOL pool_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-role-transact-sql
drop_db_role
: DROP ROLE ( IF EXISTS )? role_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-route-transact-sql
drop_route
: DROP ROUTE route_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-rule-transact-sql
drop_rule
: DROP RULE ( IF EXISTS )? (COMMA? (schema_name=id_ DOT)? rule_name=id_)?
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-schema-transact-sql
drop_schema
: DROP SCHEMA ( IF EXISTS )? schema_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-search-property-list-transact-sql
drop_search_property_list
: DROP SEARCH PROPERTY LIST property_list_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-security-policy-transact-sql
drop_security_policy
: DROP SECURITY POLICY ( IF EXISTS )? (schema_name=id_ DOT )? security_policy_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-sequence-transact-sql
drop_sequence
: DROP SEQUENCE ( IF EXISTS )? ( COMMA? (database_name=id_ DOT)? (schema_name=id_ DOT)? sequence_name=id_ )?
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-server-audit-transact-sql
drop_server_audit
: DROP SERVER AUDIT audit_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-server-audit-specification-transact-sql
drop_server_audit_specification
: DROP SERVER AUDIT SPECIFICATION audit_specification_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-server-role-transact-sql
drop_server_role
: DROP SERVER ROLE role_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-service-transact-sql
drop_service
: DROP SERVICE dropped_service_name=id_
;
// https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-signature-transact-sql
drop_signature
: DROP ( COUNTER )? SIGNATURE FROM (schema_name=id_ DOT)? module_name=id_
BY (COMMA? CERTIFICATE cert_name=id_
| COMMA? ASYMMETRIC KEY Asym_key_name=id_