iT邦幫忙

2022 iThome 鐵人賽

DAY 28
0
Software Development

新手小白的每天一點SQL系列 第 28

Day 28 SQLBolt - 12:Updating & Deleting rows

  • 分享至 

  • twitterImage
  •  

SQLBolt:https://sqlbolt.com/lesson/introduction

前言

  • 資料表(Table):每一行為唯一資料,每一列為不同屬性。

    這次我們要來修改 & 刪除資料。
    這兩個語法都要需要加上 WHERE 的條件。

SQL Lesson 14: Updating rows

語法

-- Update statement with values
UPDATE mytable
SET column = value_or_expr, 
    other_column = another_value_or_expr, 
    …
WHERE condition;

題目

-- 1. The director for A Bug's Life is incorrect, it was actually directed by John Lasseter
UPDATE movies
SET director = "John Lasseter"
WHERE id = 2;
-- 2. The year that Toy Story 2 was released is incorrect, it was actually released in 1999
UPDATE movies
SET year = 1999
WHERE id = 3;
-- 3. Both the title and director for Toy Story 8 is incorrect! The title should be "Toy Story 3" and it was directed by Lee Unkrich
UPDATE movies
SET title = "Toy Story 3", director = "Lee Unkrich"
WHERE id = 11;

SQL Lesson 15: Deleting rows

語法

-- Delete statement with condition
DELETE FROM mytable
WHERE condition;

題目

-- 1. This database is getting too big, lets remove all movies that were released before 2005.
DELETE FROM movies
where year < 2005;
-- 2. Andrew Stanton has also left the studio, so please remove all movies directed by him.
DELETE FROM movies
where director = "Andrew Stanton";

今天講解完資料操作的部分,明天就要開始介紹如何對資料表進行 新增修改刪除 啦。

參考資料:


上一篇
Day 27 SQLBolt - 11: Inserting rows
下一篇
Day 29 SQLBolt - 13:Creating tables
系列文
新手小白的每天一點SQL31
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言