Database Reference
In-Depth Information
Figure 9.3
The webpage2 table after deleting rows using pattern matching.
You will notice from Figure 9.3 that if we were to have deleted using this match we would
have removed two rows. Was this what you wanted to do with the match? A simple deletion
of a row may have resulted in our removing the Home page of our website.
Finally, you can use DELETE to completely clear all of the rows from a table as follows:
DELETE FROM webpage2
Run the above and then try to select everything from the table. You will just receive a
message saying that your query produced no results. Describing webpage 2 shows that the
table is still there, but it no longer has any data in it.
DROP TABLE
There comes a time when you not only need to delete the contents of a table but you need
to remove the table as well. To do this, use the DROP command as follows:
DROP TABLE tablename
So to finally remove all traces of webpage 2 , execute the following query:
DROP TABLE webpage2
If you now try and select anything from webpage 2 , you will get the error shown in
Figure 9.4.
You can DROP multiple tables by specifying a list of them as follows:
DROP TABLE table1, table2, table3, etc
If you are using a MySQL table type that checks for referential integrity, the DROP
TABLE command may generate errors if other tables make reference to rows in the table
being dropped. To drop a table and all others that reference it, you would use:
DROP TABLE tablename CASCADE
Search WWH ::




Custom Search