MYSQL<小筆記1– 2>

paul chou
3 min readAug 21, 2020

介紹基本的MYSQL,功能之後接下來就是CRUD 介紹

什麼事CRUD呢?就是Create, Retrieve, Update, Delete的縮寫,中文就是增、查、改、刪。這些CRUD要先設置好database 跟 create table 我上一篇也解釋道。

增:

我在上一篇文章有解釋過如何增加data,我現在想增加2本書,Taiwan Art跟 water bottle 價錢分別是150、230那SQL的命令就會是如下:

insert into books(title, price) values(‘Taiwan Art’,150),(‘water bottle’, 230);

查:

還記得select * from books這個指令嗎? * — →這個星星的意思是全部的意思,在我這個示範的版本中星星代表的是Title, Price的意思,那我可以只想知道有什麼樣的書不想知道價錢的話就可以用select title from books; 或我只想知道價錢不想知道書名的話就用select price from books;

這邊介紹一個新功能叫做where 這是一個更細的找法,篩選出結果的條件子句。

好比說,有ㄧ萬本書但我想知道Taiwan Art這本書的其他訊息,不可能一本一本慢慢看吧,那叫想像這是一個搜索鍵,我要找一本書名叫Taiwan Art

select * from books where title = ‘Taiwan Art’;

改:

好那再用Taiwan Art來舉例,如果這本書現在打折原價150元變成100元,那我們必須要改裡面的資料就要利用到update…set:

update books set price = 100(想改的) where title = ‘Taiwan Art’(什麼要改);

or 如果你知道只有Taiwan Art 是150的話

update books set price = 100(想改的) where price = 150;(什麼要改);

刪:

假使現在Taiwan Art不賣了,在上個文章中講解過如何刪Table跟Database 但還沒教過如何刪單筆資料,這很簡單那就是

delete from books where title = ‘Taiwan Art’;

這就是最基本的MYSQL指令了,現在有比較了解一點了吧,那之後我會介紹其他比較複雜的指令像是concat、join之類的。

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response