Updating data with UPDATE
Update data in the table using the UPDATE operator:
Note
We assume that you already created tables in step Creating a table and populated them with data in step Adding data to a table.
1. UPDATE episodes
2. SET title="test Episode 2"
3. WHERE
4. series_id = 2
5. AND season_id = 5
6. AND episode_id = 12
7. ;
9. COMMIT;
11. -- View result:
12. SELECT * FROM episodes WHERE series_id = 2 AND season_id = 5;
14. -- YDB doesn't see changes that take place at the start of the transaction,
15. -- which is why it first performs a read. You can't UPDATE or DELETE a table
16. -- already changed within the current transaction. UPDATE ON and
17. -- DELETE ON let you read, update, and delete multiple rows from one table
18. -- within a single transaction.
20. $to_update = (
21. SELECT series_id,
22. season_id,
23. episode_id,
24. Utf8("Yesterday's Jam UPDATED") AS title
25. FROM episodes
26. WHERE series_id = 1 AND season_id = 1 AND episode_id = 1
27. );
29. SELECT * FROM episodes WHERE series_id = 1 AND season_id = 1;
31. UPDATE episodes ON
32. SELECT * FROM $to_update;
34. COMMIT;
36. -- View result:
37. SELECT * FROM episodes WHERE series_id = 1 AND season_id = 1;
39. COMMIT;

