Documentation Home
MySQL 8.4 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.2Mb
PDF (A4) - 40.3Mb
Man Pages (TGZ) - 261.9Kb
Man Pages (Zip) - 367.5Kb
Info (Gzip) - 4.0Mb
Info (Zip) - 4.0Mb


22.4.4.4 Delete Tables

You can use thedelete() method to remove some or all records from a table in a database. The X DevAPI provides additional methods to use with thedelete() method to filter and order the records to be deleted.

Delete Records Using Conditions

The example that follows passes search conditions to thedelete() method. All records matching the condition are deleted from thecity table. In this example, one record matches the condition.

mysql-py> db.city.delete().where("Name = 'Olympia'")
Delete the First Record

To delete the first record in the city table, use thelimit() method with a value of 1.

mysql-py> db.city.delete().limit(1)
Delete All Records in a Table

You can delete all records in a table. To do so, use thedelete() method without specifying a search condition.

Caution

Use care when you delete records without specifying a search condition; doing so deletes all records from the table.

Drop a Table

Thedrop_collection() method is also used in MySQL Shell to drop a relational table from a database. For example, to drop thecitytest table from theworld_x database, issue:

mysql-py> db.drop_collection("citytest")
Related Information