1. Recap
1. Recap
In the previous unit:
We updated table names and columns
With the ALTER TABLE SQL statement, it is possible to change the name of a column or to update its data types The RENAME TABLE statement renames the specified existing table.
We updated table data
On the other hand, the UPDATE SQL keyword, part of the CRUD acronym, allows us to manipulate the values of table fields. Here's a reminder of how the syntax looks like: UPDATE table name SET columnl=valuel,column2=value2,. WHERE some_column=some_value; Remember that omitting the wHERE clause may lead to changing every value in the specified column. Proceed with caution.
We used MySQL multi-line statements
If we decide not to close SQL statements with a semicolon in the first line of the mysql command line client, the -> prompt allows us to keep inserting parts of the statement until we decide to add the trailing semicolon : Next
2. What we'll learn
It's time to experiment with the last word of the CRUD acronym: DELETE
In this unit you will learn how to:
Delete table data Delete table columns Delete entire tables Delete entire databases
: 3. Resetting the unit's databases If you make a mistake while editing any of the unit's databases or just want to reset the databases back to their original state, click the "Reset Database Section" button that is available in the relevant sections.
4. SOL DELETE
It's time to cover the last SQL keyword that forms the CRUD acronym: DELETE
Just as the UPDATE SQL keyword works together with the WHERE clause, the DELETE keyword works by specifying:
The table name The column names and the values to be deleted
DELETE FROM table_name WHERE column_name = "Value"; The WHERE clause allows us to use conditional operators in order to be more precise with our data.
Be careful with omitting the wHERE clause in a DELETE statement
Unless you do it on purpose, all your data will be deleted if you forget to add the wHERE clause.
In order to be more secure when attempting to delete data from relational databases, we will cover SQL databases security and backup measures in future units.
4. 1. Deleting values
Reset section database
If you make a mistake while editing the hotel database in this set of sections or just want to reset the database back to its original state, return to this page and click the "Reset Section Database" button below. Reset Section Database
We've created a hotel SQL database that has tables that represent part of a hotel-management application. UsE the hotel database and display its tables.
The guests table needs some data to be deleted because guests check-in and check-out from the hotel in short periods of time. Let's inspect the data from the guests table by doing a SELECT * FROM guests;:
id I name
room !
Mcpherson, Cailin C. Drake, Wade M. Randolph, Inga J.
78 81 11 77 58
| Villarreal, Channing D. 5 | Levine, Ar