Deleting Data, Tables and Databases

To DELETE data FROM a table, across all rows:

mysql> delete from Students ;
Query OK, 8 rows affected (0.04 sec)

 

TRUNCATE table, provides the same result:

mysql> truncate Students ;
Query OK, 0 rows affected (0.11 sec)

 

 

To DELETE a row in a table, use WHERE to select either a group or unique field data :

mysql> delete from Students where id = ‘4’ ;
Query OK, 1 row affected (0.05 sec)

 

Selecting a field with with the same value in multiple records will delete all those records containing that specified value:

mysql> delete from Students where Town = ‘London’ ;
Query OK, 3 rows affected (0.07 sec)

 

 

To delete a table, use DROP TABLE :

mysql> drop table Students ;
Query OK, 0 rows affected (0.05 sec)

 

 

To delete a database, use DROP DATABASE :

mysql> drop database Academy ;
Query OK, 0 rows affected (0.00 sec)

Leave a Reply