https://de.wikipedia.org/w/api.php?action=feedcontributions&feedformat=atom&user=CodeNaked Wikipedia - Benutzerbeiträge [de] 2025-05-12T07:36:29Z Benutzerbeiträge MediaWiki 1.44.0-wmf.28 https://de.wikipedia.org/w/index.php?title=Update_(SQL)&diff=179502596 Update (SQL) 2006-11-14T16:30:06Z <p>CodeNaked: Reverted edits by 192.91.172.42 to previous version by CodeNaked (ex. change did not match explanation).</p> <hr /> <div>A [[relational database management system]] uses [[SQL]] '''&lt;code&gt;UPDATE&lt;/code&gt;''' statements to change data in one or more records. Either all the rows can be updated, or a subset may be chosen using a [[condition (SQL)|condition]].<br /> <br /> &lt;code&gt;UPDATE&lt;/code&gt; statement has the following form:<br /> <br /> :'''&lt;code&gt;UPDATE&lt;/code&gt;''' ''table_name'' '''&lt;code&gt;SET&lt;/code&gt;''' ''column_name'' = ''value'' [, ''column_name'' = ''value ...''] ['''&lt;code&gt;WHERE&lt;/code&gt;''' ''condition''];<br /> <br /> For the &lt;code&gt;UPDATE&lt;/code&gt; to be successful, the user must have data manipulation privileges (&lt;code&gt;UPDATE&lt;/code&gt; privilege) over the table or column, the updated value must not conflict with all the applicable constraints (such as [[primary key]]s, unique indexes, [[Check_Constraint|&lt;code&gt;CHECK&lt;/code&gt; constraints]], and [[Null_%28SQL%29|&lt;code&gt;NOT NULL&lt;/code&gt;]] constraints). <br /> <br /> ==Examples==<br /> <br /> Set the value of column ''C1'' in table ''T'' column to 1, only if in that row the value of ''C2'' is &quot;a&quot;.<br /> <br /> UPDATE T SET C1 = 1 WHERE C2 = 'a';<br /> <br /> Increase value of column ''C1'' by 1 if ''C2'' is &quot;a&quot;.<br /> <br /> UPDATE T SET C1 = C1 + 1 WHERE C2 = 'a';<br /> <br /> Prepend column ''C1'' with the string &quot;text&quot; if ''C2'' is &quot;a&quot;.<br /> <br /> UPDATE T SET C1 = CONCAT( 'text' , C1 ) WHERE C2 = 'a';<br /> <br /> Mass update example: Set the value of column ''C1'' in table ''T1'' to 2, only if the value of column ''C2'' is found in the sub list of values in column ''C3'' in table ''T2'' having the column ''C4'' equal to 0. <br /> <br /> UPDATE T1 <br /> SET <br /> C1 = 2 <br /> WHERE C2 in (SELECT C3<br /> FROM T2<br /> WHERE C4 = 0);<br /> <br /> You may also update multiple fields in a single update statement:<br /> <br /> UPDATE test SET C1 = 1, C2 = 2;<br /> <br /> {{Databases}}<br /> [[Category:SQL statements]]<br /> {{compu-lang-stub}}<br /> <br /> [[cs:UPDATE]]<br /> [[nl:Update (SQL)]]</div> CodeNaked https://de.wikipedia.org/w/index.php?title=Update_(SQL)&diff=179502594 Update (SQL) 2006-11-03T19:53:06Z <p>CodeNaked: Revert edits by 61.11.77.129 to previous version by 129.230.248.1</p> <hr /> <div>A [[relational database management system]] uses [[SQL]] '''&lt;code&gt;UPDATE&lt;/code&gt;''' statements to change data in one or more records. Either all the rows can be updated, or a subset may be chosen using a [[condition (SQL)|condition]].<br /> <br /> &lt;code&gt;UPDATE&lt;/code&gt; statement has the following form:<br /> <br /> :'''&lt;code&gt;UPDATE&lt;/code&gt;''' ''table_name'' '''&lt;code&gt;SET&lt;/code&gt;''' ''column_name'' = ''value'' [, ''column_name'' = ''value ...''] ['''&lt;code&gt;WHERE&lt;/code&gt;''' ''condition''];<br /> <br /> For the &lt;code&gt;UPDATE&lt;/code&gt; to be successful, the user must have data manipulation privileges (&lt;code&gt;UPDATE&lt;/code&gt; privilege) over the table or column, the updated value must not conflict with all the applicable constraints (such as [[primary key]]s, unique indexes, [[Check_Constraint|&lt;code&gt;CHECK&lt;/code&gt; constraints]], and [[Null_%28SQL%29|&lt;code&gt;NOT NULL&lt;/code&gt;]] constraints). <br /> <br /> ==Examples==<br /> <br /> Set the value of column ''C1'' in table ''T'' column to 1, only if in that row the value of ''C2'' is &quot;a&quot;.<br /> <br /> UPDATE T SET C1 = 1 WHERE C2 = 'a';<br /> <br /> Increase value of column ''C1'' by 1 if ''C2'' is &quot;a&quot;.<br /> <br /> UPDATE T SET C1 = C1 + 1 WHERE C2 = 'a';<br /> <br /> Prepend column ''C1'' with the string &quot;text&quot; if ''C2'' is &quot;a&quot;.<br /> <br /> UPDATE T SET C1 = CONCAT( 'text' , C1 ) WHERE C2 = 'a';<br /> <br /> Mass update example: Set the value of column ''C1'' in table ''T1'' to 2, only if the value of column ''C2'' is found in the sub list of values in column ''C3'' in table ''T2'' having the column ''C4'' equal to 0. <br /> <br /> UPDATE T1 <br /> SET <br /> C1 = 2 <br /> WHERE C2 in (SELECT C3<br /> FROM T2<br /> WHERE C4 = 0);<br /> <br /> You may also update multiple fields in a single update statement:<br /> <br /> UPDATE test SET C1 = 1, C2 = 2;<br /> <br /> {{Databases}}<br /> [[Category:SQL statements]]<br /> {{compu-lang-stub}}<br /> <br /> [[cs:UPDATE]]<br /> [[nl:Update (SQL)]]</div> CodeNaked