ORIGIN

Database Project: SQL Grammar Analysis Ⅰ

Database Project 1 mins278 words

This is a very simple version of SQL grammar. For the sake of time, I just write some very basic usage.

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
<SQLStatement> ::= <CreateTable>
| <DropTable>
| <DeleteStatement>
| <UpdateStatement>
| <SelectStatement>
| <InsertStatement>

<CreateTable> ::= CREATE TABLE Table_Name L_BRACKET
<ColumnDefine>
R_BRACKET

<ColumnDefine> ::= Column_Name Data_Types [, <ColumnDefine> ]

<DropTable> ::= DROP TABLE <Table_Names>

<Table_Names> ::= Table_Name [, <Table_Names> ]

<DeleteStatement> ::= DELETE FROM Table_Name WHERE <Expression>

<UpdateStamtement> ::= UPDATE Table_Name
SET <Assign_Statement>
[WHERE <Expression> ]

<Assign_Statement> ::= Column_Name EQUAL <Value>
[, <Assign_Statement> ]

<Value> ::= NUMBER | STRING | NULL | TRUE | FALSE

<SelectStatement> ::= SELECT (STERISK | <SelectList>)
FROM <TableList>
[WHERE <Expression> ]

<SelectList> ::= (Table_Name DOT (ASTERISK | Column_Name) | Column_Name)
[AS New_Column_Name] [, <SelectList> ]

<TableList> ::= Table_Name
| L_BRACKET <SelectStatement> R_BRACKET

<Expression> ::= <ExpressionFirstPart> <ExpressionTail>

<ExpressionFirstPart> ::= <Function>
| <Value>
| [Table_Name DOT] Column_Name
| L_BRACKET <Expression> R_BRACKET
| Unary_Operator <Expression>
| [[NOT] EXISTS] L_BRACKET <SelectStatement> R_BRACKET

<ExpressionTail> ::= <BinaryOperator> <Expression>
| IS [NOT] NULL
| [NOT] IN L_BRACKET <SelectStatement> R_BRACKET
| [NOT] BETWEEN <Expression> AND <Expression>
| <empty>

<BinaryOperator> ::= (ASTERISK | DIV | MOD)
| (PLUS | MINUS)
| (LESS_THEN | LESS_EQUAL_TO | GREATER_THAN | GREATER_EQUAL_TO)
| (EQUAL | NOT_EQUAL | IS | IS NOT | IN)
| AND
| OR
| IS [NOT]

<InsertStatement> ::= INSERT INTO Table_Name
[L_BRACKET <ColumnList> R_BRACKET]
VALUES L_BRACKET <ValueList> R_BRACKET

<ColumnList> ::= Column_Name [, Column_Name]

<ValueList> ::= <Value> [, <Value> ]
TOP
COMMENT
  • ABOUT
  • |
o_oyao
  The Jigsaw puzzle is incomplete with even one missing piece. And I want to be the last piece to make the puzzle complete.
Like my post?
Default QR Code
made with ❤️ by o_oyao
©o_oyao 2019-2024

|