DELETE
SQL statement
Description
Deletes the rows in TableName specified by Criteria.
Syntax
|
1 |
DELETE FROM TableName WHERE Criteria {USING TransactionObject}; |
|
Parameter |
Description |
|---|---|
|
TableName |
The name of the table from which you want to delete |
|
Criteria |
Criteria that specify which rows to |
|
TransactionObject |
The name of the transaction object that identifies |
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
Example 1
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 ; |
Example 2
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 2 3 4 |
int Emp_num Emp_num = Integer(sle_number.Text) DELETE FROM Employee 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.