Transcript for:
Guide to Update and Delete Database Data

Hey everybody, in this video I'm going to show you how we can update and delete data from a table. In my example, we have a table of employees. However, Sheldon Plankton is missing some information, an hourly pay, and a hire date.

Let's update those fields. To update some data in a table, we would use the update keyword, the name of the table, employees in my example, Then set. Which column would we like to interact with first? Let's interact with hourly pay. Set hourly pay.

Let's pay Plankton $10.25 per hour. We should probably add a WHERE clause. I need to specifically select Plankton. WHERE, let's select his employee ID. WHERE employee ID equals 6. then semicolon to end the statement.

You could also select Plankton by his first name or last name as well. When I execute the script, Plankton's hourly pay is now $10.25 per hour. To update multiple columns, you can change more than one field at once.

After your first change, you can add a comma. Then change another field. Let's change Plankton's hire date to be the following.

Hire date equals 10-23-0-07. I'll make his hourly pay $10.50. I'm feeling generous. Here we are. Plankton's hourly pay is now $10.50.

His hire date is January 7th, 2023. To set a field to null, meaning no value, you would just say equals null. For example, let's take Plankton's hire date, set the hire date equal to null. Plankton's hire date is now null.

So maybe we're gonna fire him or something. In this next example, I'll give you a demonstration but you don't want to follow along. To update all of the rows within a column, you would exclude the WHERE clause.

If I were to set hourly pay, equal to 1025, that would affect all of the rows. After executing this statement, the hourly pay for everybody is now 1025. That's an example of how you could set a column to be one consistent value. To delete a row from a table, you would type delete from the name of the table.

Now don't write just the statement. It will delete all rows in your table. Here's an example. Do not do this. I will delete from employees.

There, my whole table is gone. Do not do this. Be sure to add a WHERE clause when deleting from a table. Otherwise, this will delete all your rows.

WHERE employeeId equals 6. Yep, and Plankton is no longer there. Alright everybody, that is a super quick video on how to update and delete data from a table.