Để cập nhật dữ liệu trên bảng chúng ta sử dụng câu lệnh update, ví dụ dưới sẽ cập nhật tuổi của user với username là johndoe:
mysql> update users set age = 22 where username = 'johndoe';
Để kiểm tra lại giá trị mới được cập nhật cho user với username là johndoe, dùng câu lệnh sau:
mysql> select * from users where username = 'johndoe';
Để cập nhật toàn bộ dữ liệu trên bảng, bỏ mệnh để where ra khỏi câu lệnh update. Trong ví dụ sau, chúng ta sẽ cập nhật toàn bộ tuổi của user có trong bảng:
mysql> update users set age = 25;
Để kiểm tra tuổi mới được cập nhật dùng câu lệnh sau:
mysql> select age from users;Nguồn: CodeHub.vn
Không có nhận xét nào:
Đăng nhận xét