Home [SQL] Update 更新資料
Post
Cancel

[SQL] Update 更新資料

語法

1
2
3
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

範例1

將桌上型電腦(id=1)的進貨單價改成100000

1
2
3
4
--將桌上型電腦(id=1)的進貨單價改成100000
update 商品清單
set 進貨單價 = 100000
where 商品ID=1

執行結果:

1
2
3
4
select * from 商品清單 where 商品ID=1

商品ID	商品名稱	群組名稱	進貨單價	販賣單價
1	桌上型電腦	電腦主機	100000	180000

範例2

The following SQL statement updates the first customer (CustomerID = 1) with a new contact person and a new city.

1
2
3
UPDATE Customers
SET ContactName = 'Alfred Schmidt', City= 'Frankfurt'
WHERE CustomerID = 1;

The selection from the “Customers” table will now look like this:

1
2
3
4
5
6
7
8
9
10
CustomerID	CustomerName	ContactName	Address	City	PostalCode	Country
1

Alfreds Futterkiste	Alfred Schmidt	Obere Str. 57	Frankfurt	12209	Germany
2	Ana Trujillo Emparedados y helados	Ana Trujillo	Avda. de la Constitución 2222	México D.F.	05021	Mexico
3	Antonio Moreno Taquería	Antonio Moreno	Mataderos 2312	México D.F.	05023	Mexico
4

Around the Horn	Thomas Hardy	120 Hanover Sq.	London	WA1 1DP	UK
5	Berglunds snabbköp	Christina Berglund	Berguvsvägen 8	Luleå	S-958 22	Sweden

w3schools - SQL UPDATE Statement

This post is licensed under CC BY 4.0 by the author.