We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
MySQL: How to UPDATE and DELETE data from a TABLE
0:00 hey everybody in this video I'm going to
0:02 show you how we can update and delete
0:04 data from a table
0:06 in my example we have a table of
0:08 employees however Sheldon Plankton is
0:11 missing some information and hourly pay
0:13 and a higher date let's update those
0:15 fields to update some data in a table we
0:18 would use the update keyword
0:22 the name of the table
0:24 employees in my example
0:26 then set which column would we like to
0:30 interact with first let's interact with
0:32 hourly pay set hourly
0:36 pay
0:38 let's pay Plankton ten dollars and 25
0:41 cents per hour we should probably add a
0:44 where Clause I need to specifically
0:47 select Plankton where
0:50 let's select his employee ID where
0:53 employee ID equals six
0:58 then semicolon to end the statement
1:01 you could also select Plankton by his
1:03 first name or last name as well when I
1:06 execute the script
1:09 Plankton's hourly pay is now 10.25 cents
1:13 per hour
1:14 to update multiple columns you can
1:18 change more than one field at once after
1:21 your first change you can add a comma
1:24 then change another field let's change
1:27 Plankton's higher date to be the
1:29 following higher date equals
1:34 10
1:36 23-0 Dash
1:38 zero seven
1:39 I'll make his hourly pay 10.50 I'm
1:42 feeling generous
1:46 here we are Plankton's hourly pay is now
1:48 ten dollars fifty cents his higher date
1:51 is January 7th 2023.
1:55 to set a field to null meaning no value
1:58 you would just say equals null for
2:01 example let's take Plankton's higher
2:03 date
2:05 set the higher date equal to null
2:10 Plankton's higher date is now null
2:13 so maybe we're gonna fire him or
2:15 something
2:16 in this next example I'll give you a
2:18 demonstration but you don't want to
2:19 follow along to update all of the rows
2:22 within a column you would exclude the
2:25 where clause
2:26 if I were to set hourly pay equal to
2:29 10.25 that would affect all of the rows
2:32 after executing this statement
2:35 the hourly pay for everybody is now
2:38 10.25. that's an example of how you
2:41 could set a column to be one consistent
2:43 value
2:45 to delete a row from a table
2:47 you would type delete
2:50 from the name of the table
2:53 now don't write just the statement it
2:56 will delete all rows in your table
2:57 here's an example do not do this I will
3:01 delete from employees
3:04 there my whole table is gone do not do
3:06 this be sure to add a where Clause when
3:09 deleting from a table otherwise this
3:11 will delete all your rows where
3:14 employee ID
3:16 equals six
3:20 yep and Plankton is no longer there all
3:23 right everybody that is a super quick
3:25 video on how to update and delete data
3:28 from a table
0:00 Xin chào mọi người! Trong video này, tôi sẽ hướng dẫn các bạn cách cập nhật và xóa dữ liệu trong một bảng.
0:06 Ví dụ của tôi là bảng nhân viên. Tuy nhiên, thông tin về Sheldon Plankton còn thiếu một số mục, cụ thể là mức lương theo giờ và ngày bắt đầu làm việc. Chúng ta sẽ cập nhật những thông tin này.
0:15 Để cập nhật dữ liệu trong bảng, chúng ta sử dụng từ khóa "update", sau đó là tên bảng ("employees" trong ví dụ này), rồi đến "set" và tên cột muốn chỉnh sửa. Đầu tiên, chúng ta sẽ chỉnh sửa mức lương theo giờ: "set hourly pay".
0:38 Giả sử chúng ta trả cho Plankton 10 đô la 25 xu một giờ. Chúng ta nên thêm mệnh đề "where" để chọn đúng đối tượng. Cụ thể là chọn Plankton: "where" ID nhân viên của anh ấy "where employee ID equals six", sau đó là dấu chấm phẩy để kết thúc câu lệnh.
1:01 Bạn cũng có thể chọn Plankton bằng tên hoặc họ. Sau khi chạy lệnh này, mức lương theo giờ của Plankton sẽ là 10 đô la 25 xu.
1:14 Để cập nhật nhiều cột, bạn có thể thay đổi nhiều trường cùng lúc. Sau thay đổi đầu tiên, thêm dấu phẩy rồi thay đổi trường khác. Ví dụ, thay đổi ngày bắt đầu làm việc của Plankton thành: "hire date equals 10-23-07".
1:39 Tôi sẽ tăng lương theo giờ của anh ấy lên 10 đô la 50; hôm nay tôi hào phóng.
1:46 Xong! Mức lương theo giờ của Plankton bây giờ là mười đô la năm mươi xu; ngày bắt đầu làm việc của anh ấy là ngày 23 tháng 10 năm 2007.
1:55 Để đặt một trường thành null, nghĩa là không có giá trị, bạn chỉ cần viết "equals null". Ví dụ: chúng ta sẽ đặt ngày bắt đầu làm việc của Plankton thành null.
2:10 Ngày bắt đầu làm việc của Plankton bây giờ là null, có lẽ chúng ta nên sa thải anh ta thì hơn.
2:16 Trong ví dụ tiếp theo, tôi sẽ cho bạn xem một thao tác, nhưng đừng làm theo nhé. Để cập nhật tất cả các hàng trong một cột, bạn sẽ bỏ qua mệnh đề "where".
2:26 Nếu tôi đặt mức lương theo giờ bằng 10 đô la 25 xu, điều đó sẽ ảnh hưởng đến tất cả các hàng. Sau khi chạy câu lệnh này, mức lương theo giờ của tất cả mọi người sẽ là 10 đô la 25 xu. Đó là một ví dụ về cách bạn có thể đặt một cột thành một giá trị duy nhất.
2:45 Để xóa một hàng khỏi bảng, bạn nhập "delete from" và tên bảng.
2:53 Tuyệt đối đừng chỉ viết câu lệnh này không thôi, vì nó sẽ xóa tất cả các hàng trong bảng của bạn. Đây là một ví dụ: đừng làm theo! Tôi sẽ "delete from employees".
3:04 Xong! Toàn bộ bảng của tôi đã biến mất! Đừng làm điều này! Hãy nhớ thêm mệnh đề "where" khi xóa dữ liệu khỏi bảng; nếu không, nó sẽ xóa tất cả các hàng: "where employee ID equals six".
3:20 Đúng vậy, và Plankton đã biến mất. Vậy là xong, một video siêu nhanh về cách cập nhật và xóa dữ liệu khỏi một bảng.
Translated At: 2025-02-23T11:25:55Z
Translate Version: 3.1 Improved translation step with full context