English | 正體中文 | 简体中文

SQL update


范例资料表 : Songs (以下范例皆用此表当作资料来源)
Artist SongTitle SongPlayCount
Scott Mckenzie San Francisco 30
Kiss Detroit rock city 120
R.E.M. Losing my religion 256
Pink Try 97


Example
更新所有资料列里'Artist'栏位的值

Sytax : Update table_name SET col_name = value
SQL
UPDATE Songs SET Artist = 'Maroon 5'

会输出结果
Artist SongTitle SongPlayCount
Maroon 5 San Francisco 30
Maroon 5 Detroit rock city 120
Maroon 5 Losing my religion 256
Maroon 5 Try 97


Example
同时更新在所有资料列里多个栏位的值

Sytax : Update table_name SET col_name1 = value1, col_name2 = value2, col_name3 = value3 ...
SQL
UPDATE Songs SET Artist = 'Maroon 5', SongPlayCount = 100

会输出结果
Artist SongTitle SongPlayCount
Maroon 5 San Francisco 100
Maroon 5 Detroit rock city 100
Maroon 5 Losing my religion 100
Maroon 5 Try 100


Example
更新指定的资料列里'SongPlayCount'栏位的值

Sytax : Update table_name SET col_name = value WHERE seacrch_condition
SQL
UPDATE Songs SET SongPlayCount = 2000 WHERE Artist = 'Kiss' 

会输出结果
Artist SongTitle SongPlayCount
Scott Mckenzie San Francisco 30
Kiss Detroit rock city 2000
R.E.M. Losing my religion 256
Pink Try 97

© 2012 PureExample.com contact