For faster navigation, this Iframe is preloading the Wikiwand page for Update.

Update

此条目没有列出任何参考或来源。 (2014年4月1日)维基百科所有的内容都应该可供查证。请协助补充可靠来源改善这篇条目。无法查证的内容可能会因为异议提出而被移除。

SQL里,可以利用UPDATE语句修改资料表中一笔或多笔的资料。可以更新全部的字段,或使用条件式只更新部分的资料。

以下是Update语句的语法:

UPDATE 资料表名称 SET [字段名称1 = 值1], [ 字段名称2 = 值2], [ 字段名称3 = 值 ...] [WHERE 条件式]


UPDATE若要能成功,用户必须要有字段或是资料表的资料存取权限(UPDATE权限),而且更新的值不可违背资料表的限制条件(如主键、唯一索引、检查限制或非空值等限制)。

示例

只在字段 C2 的值为“ a ”时将资料表 T 中的字段 C1 设为 1 。

UPDATE T SET C1 = 1 WHERE C2 = 'a'

将字段 C1 的值加 1 ,若字段 C2 的值为“ a ”。

UPDATE T SET C1 = C1 + 1 WHERE C2 = 'a'

将字段 C1 的前面串接上字符串“ text ”,若字段 C2 的值为“ a ”。

UPDATE T SET C1 = 'text' || C1 WHERE C2 = 'a'

只在 C2 的值也出现于有着字段 C4 等于 0 的资料表 T2 里的字段 C3 中时,资料表 T1 里的字段 C1 才会被设为 2 。

UPDATE T1 
SET    C1 = 2    
WHERE  C2 IN ( SELECT C3
               FROM   T2
               WHERE  C4 = 0)

参考文献

参见

{{bottomLinkPreText}} {{bottomLinkText}}
Update
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?