Cập nhật truy vấn sql trong phpmyadmin
Câu lệnh Show Cú pháp cơ bản của câu lệnh CẬP NHẬT tên_bảng SET cột1=giá trị, cột2=giá trị2,. WHERE column_name=some_value Hãy tạo một truy vấn SQL bằng cách sử dụng câu lệnh +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+ Đoạn mã PHP trong ví dụ sau sẽ cập nhật địa chỉ email của một người trong bảng người có id bằng 1 Ví dụPDO hướng đối tượng thủ tục Tải xuống____3____4Sau khi cập nhật, bảng người sẽ giống như thế này +----+------------+-----------+--------------------------+ | id | first_name | last_name | email | +----+------------+-----------+--------------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+--------------------------+ Cảnh báo. Mệnh đề Để cập nhật “Tuổi” của một người có “ID” là 201 trong bảng “Dữ liệu”, chúng ta có thể sử dụng đoạn mã sau Cập nhật truy vấn bằng phương pháp thủ tục +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+4 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+5 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+6 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+7 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+8 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+90123____150 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+51 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+52 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+531 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+6 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+56 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+8 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+58 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+59 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+60 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+633____165 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+66 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+67 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+68 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+69 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+70 Đầu ra. Đầu ra trên Trình duyệt web Cập nhật truy vấn bằng phương pháp hướng đối tượng +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+4 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+5 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+6 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+74 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+8 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+76 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+771 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+793____181 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+82 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+83 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+53 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+86 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+873____189 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+903____165 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+93____194 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+53 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+96 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+70 Đầu ra. Đầu ra trên Trình duyệt web Cập nhật truy vấn bằng phương pháp PDO +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+4 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+5003______1603 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+8 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+76 0607 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+809 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+591112 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+81415 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+531003____1863____2313____189203____23637____224 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+53 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+500 +----+------------+-----------+----------------------+ | id | first_name | last_name | email | +----+------------+-----------+----------------------+ | 1 | Peter | Parker | [email protected] | | 2 | John | Rambo | [email protected] | | 3 | Clark | Kent | [email protected] | | 4 | John | Carter | [email protected] | | 5 | Harry | Potter | [email protected] | +----+------------+-----------+----------------------+70 Đầu ra. Đầu ra trên Trình duyệt web PHP là ngôn ngữ kịch bản phía máy chủ được thiết kế dành riêng cho phát triển web. Bạn có thể học PHP từ đầu bằng cách làm theo Hướng dẫn PHP và Ví dụ về PHP này Làm cách nào để CẬP NHẬT một truy vấn trong MySQL?Điều này sẽ sửa đổi bất kỳ giá trị trường nào của bất kỳ bảng MySQL nào. . cú pháp. Khối mã sau đây có cú pháp SQL chung của lệnh CẬP NHẬT để sửa đổi dữ liệu trong bảng MySQL − CẬP NHẬT tên_bảng SET trường1 = giá trị mới1, trường2 = giá trị mới2 [Điều khoản WHERE]. Ví dụ. . cú pháp. . Ví dụ Làm cách nào để CẬP NHẬT bản ghi trong phpmyadmin?Sử dụng cây điều hướng ở thanh bên trái để tìm bảng cơ sở dữ liệu mà bạn muốn sửa đổi. . Các trường cơ sở dữ liệu được hiển thị trong khung bên phải. . Bây giờ bạn có thể tiến hành sửa đổi dữ liệu trong trường Nếu bạn muốn sửa đổi chi tiết bảng, hãy chọn tab Hoạt động ở đầu màn hình Truy vấn CẬP NHẬT trong SQL là gì?Một câu lệnh UPDATE SQL thay đổi dữ liệu của một hoặc nhiều bản ghi trong một bảng. Tất cả các hàng có thể được cập nhật hoặc một tập hợp con có thể được chọn bằng một điều kiện. Câu lệnh UPDATE có dạng sau. CẬP NHẬT tên_bảng SET tên_cột = giá trị [, tên_cột = giá trị. ]
Làm cách nào để thêm hoặc CẬP NHẬT truy vấn SQL?Lệnh INSERT OR UPDATE là phần mở rộng của lệnh INSERT, với những điểm khác biệt này. . Nếu hàng được chèn không tồn tại, INSERT OR UPDATE thực hiện thao tác INSERT Nếu hàng được chèn đã tồn tại, CHÈN HOẶC CẬP NHẬT thực hiện thao tác CẬP NHẬT, cập nhật hàng với các giá trị cột được chỉ định |