DELETE SQL statement
Description
Deletes the rows in TableName specified
by Criteria.
Syntax
|
1 |
DELETE FROM <span>TableName</span> WHERE <span>Criteria</span> {USING <span>TransactionObject</span>}; |
|
Parameter |
Description |
|---|---|
|
TableName |
The name of the table from which you |
|
Criteria |
Criteria that specify which rows to delete. |
|
TransactionObject |
The name of the transaction object that |
Usage
Error handling
It is good practice to test the success/failure code
after executing a DELETE statement. To see if
the DELETE was successful, you can test SLQCode
for a failure code. However, if nothing matches the WHERE clause
and no rows are deleted, SQLCode is
still set to zero. To make sure the delete affected at least one
row, check the SQLNRows property
of the transaction object.
Examples
This statement deletes rows from the Employee table in the database
specified in the default transaction object where Emp_num
is less than 100:
|
1 |
DELETE FROM Employee WHERE Emp_num < 100 ; |
These statements delete rows from the Employee table
in the database named in the transaction object named Emp_tran where Emp_num is equal
to the value entered in the SingleLineEdit sle_number:
|
1 |
int Emp_num |
|
1 |
Emp_num = Integer(sle_number.Text) |
|
1 |
DELETE FROM Employee |
|
1 |
WHERE Employee.Emp_num = :Emp_num ; |
The integer Emp_num requires
a colon in front of it to indicate it is a variable when it is used
in a WHERE clause.