O'Reilly logo

Drupal 8 Module Development by Daniel Sipos

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Delete queries

Lastly, we can also get rid of our records using the DELETE query:

$result = $database->delete('players')  ->condition('name', 'Micheal P.')  ->execute();

All the records that match the condition will get removed. Be careful with this because as with update queries, leaving out a condition will basically truncate your table, and the query will return the number of records affected, that is, deleted.

Although you can make SELECT queries against entity and field tables to find the IDs of the entities you want to load, you should never perform INSERT, UPDATE, or DELETE queries against these tables. You run a very high risk of corrupting your data.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required