Deleting Rows from a Table

This tutorial describes how to delete rows from a database table.

Introduction

The deletion of a record from a database can be performed by executing the DELETE SQL statement. The query does not pass or return any data.

Basic procedure

  • Configure the SQL statement

  • Execute the statement.

Detailed steps

Configure the SQL statement

Create a literal for your DELETE statement. You do not need to create a RSqlStatement object to run a DELETE statement. You need to just execute the query with the RSqlDatabase object, which has its own RSqlDatabase::Exec() function taking a query string as its parameter.

_LIT(kQueryString,"DELETE FROM countries WHERE population < 2;"); 

NOTE : It is possible to call a DELETE statement from an RSqlStatement object, but it is computationally more expensive and you are recommended not to do so.

Execute the statement

Execute the DELETE statement. This code assumes that the countriesDatabase object is open.

countriesDatabase.Exec(kQueryString);