DELETE Statement
<sql> ::= <delete_statement>
<delete_statement> ::= "DELETE" ["PERMANENTLY"] "FROM" <table_name> ["USING" <table_list>] ["WHERE" <condition>]
<table_list> ::= <table_name> ["," <table_name>]*
<condition> ::= <expression> ["AND" <expression>]*
<expression> ::= <column_name> <operator> <value>
<operator> ::= "=" | "<>" | "<" | ">" | "<=" | ">=" | "IS NOT NULL"
<table_name> ::= [a-zA-Z_][a-zA-Z0-9_.]*
<column_name> ::= [a-zA-Z_][a-zA-Z0-9_]*
<value> ::= <literal> | <parameter>
<literal> ::= '"[^"]*"' | "'[^']*'" | [0-9]+
<parameter> ::= "&" [a-zA-Z_][a-zA-Z0-9_]*
Explanation
-
SQL Statement Types (
<sql>
): The BNF defines the primary type of SQL statement -DELETE
. -
DELETE Statement (
<delete_statement>
): ADELETE
statement starts withDELETE
, optionally followed byPERMANENTLY
for delete records physically, followed byFROM
and a table name. Optionally, it may include aUSING
clause to specify additional tables involved in the deletion and aWHERE
clause to filter rows. -
Components:
- Table List (
<table_list>
): Defines one or more tables used in theUSING
clause. - Condition (
<condition>
): Specifies filtering conditions forWHERE
clauses. - Expression (
<expression>
): Represents a conditional expression that compares a column with a value using an operator. - Operators (
<operator>
): Defines the comparison operators, such as=
,<>
,<
,>
,<=
,>=
, andIS NOT NULL
.
- Table List (
-
Table and Column Naming:
- Table Name (
<table_name>
): Represents the name of the table, following typical SQL naming conventions. - Column Name (
<column_name>
): Represents the name of a column, following typical SQL naming conventions.
- Table Name (
-
Values:
- Literal (
<literal>
): Represents a value such as a string or number. - Parameter (
<parameter>
): Represents a parameter that starts with&
.
- Literal (
Example 1
delete PERMANENTLY from dictionary.events
where id=100;
Example 2
delete PERMANENTLY from Contract.tokenminterc20token;
Example 3
delete from dictionary.users where ref = &ref::UUID;
Example 4
DELETE FROM Operation.operation_order
WHERE ref in ("58b62115-6f06-abc1-225f-e98fb8c9582c", "621b8392-4614-264a-6d43-87b99366ae84", "2e1d0a11-8874-bb66-f694-ca7e3a33f4f1");
Example 5
DELETE FROM Operation.operation_order
WHERE ref = "3b0a32dd-a977-4b29-8ccf-ca031b5f7147";