用EBNF表示sql 的词法规则
时间: 2023-06-05 19:05:41 浏览: 73
我可以为您解答这个问题。以下是 SQL 的 EBNF 词法规则:
<statement> ::= <data_manipulation_statement>
| <transaction_statement>
| <data_definition_statement>
| <session_control_statement>
<data_manipulation_statement> ::= <select_statement>
| <insert_statement>
| <update_statement>
| <delete_statement>
<select_statement> ::= SELECT <select_list> FROM <table_name>
WHERE <search_condition>
GROUP BY <group_by_clause>
HAVING <search_condition>
<insert_statement> ::= INSERT INTO <table_name> (<column_list>)
VALUES (<value_list>)
<update_statement> ::= UPDATE <table_name> SET <set_clause>
WHERE <search_condition>
<delete_statement> ::= DELETE FROM <table_name> WHERE <search_condition>
<transaction_statement> ::= <commit_statement> | <rollback_statement>
<data_definition_statement> ::= <create_statement>
| <alter_statement>
| <drop_statement>
<session_control_statement> ::= SET <option> = <value>
<create_statement> ::= CREATE TABLE <table_name>
(<column_definition_list>)
<alter_statement> ::= ALTER TABLE <table_name>
<add_or_drop_constraint_clause>
<drop_statement> ::= DROP TABLE <table_name>
<column_list> ::= <column_name> [, <column_name>]*
<value_list> ::= <value> [, <value>]*
<set_clause> ::= <column_name> = <value> [, <column_name> = <value>]*
<group_by_clause> ::= <column_name> [, <column_name>]*
<search_condition> ::= <comparison_predicate>
| <logical_predicate>
| <search_condition> AND <search_condition>
| <search_condition> OR <search_condition>
<comparison_predicate> ::= <column_name> <comparison_operator> <value>
<logical_predicate> ::= <comparison_predicate>
| NOT <comparison_predicate>
| <search_condition> AND <logical_predicate>
| <search_condition> OR <logical_predicate>
<add_or_drop_constraint_clause> ::= ADD <constraint_definition>
| DROP <constraint_name>
<constraint_definition> ::= <unique_constraint>
| <primary_key_constraint>
| <foreign_key_constraint>
<unique_constraint> ::= UNIQUE (<column_name> [, <column_name>]*)
<primary_key_constraint> ::= PRIMARY KEY (<column_name> [, <column_name>]*)
<foreign_key_constraint> ::= FOREIGN KEY (<column_name> [, <column_name>]*)
REFERENCES <table_name> (<column_name> [, <column_name>]*)
<comparison_operator> ::= = | != | < | <= | > | >=
<option> ::= TRANSACTION ISOLATION LEVEL | AUTOCOMMIT
<value> ::= <string> | <number>
其中,<table_name>,<column_name>,<constraint_name>,<string>,<number> 为终结符。
相关推荐
![application/x-zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)