Opentopia Directory Encyclopedia Tools

Update (SQL)

Encyclopedia : U : UP : UPD : Update (SQL)


A relational database management system uses SQL UPDATE 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.

UPDATE statement has the following form:

UPDATE table_name SET column_name = value [, column_name = value ...] [WHERE condition]
For the UPDATE to be successful, the user must have data manipulation privileges (UPDATE privilege) over the table or column, the updated value must not conflict with all the applicable constraints (such as primary keys, unique indexes, CHECK constraints, and NOT NULL constraints).

Examples

Set the value of column C1 in table T column to 1, only if in that row the value of C2 is "a".

UPDATE T SET C1 = 1 WHERE C2 = 'a';
Increase value of column C1 by 1 if C2 is "a".

UPDATE T SET C1 = C1 + 1 WHERE C2 = 'a';
Prepend column C1 with the string "text" if C2 is "a".

UPDATE T SET C1 = CONCAT( 'text' , C1 ) WHERE C2 = 'a';
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.

UPDATE T1
SET
C1 = 2
WHERE C2 in (SELECT C3
FROM   T2
WHERE C4 = 0);
You may also update multiple fields in a single update statement:

UPDATE test SET C1 = 1, C2 = 2;
Topics in database management systems (DBMS)[ view][ talk][ edit] )
Concepts
Database | Database model | Relational database | Relational model | Relational algebra | Primary key - Foreign key - Surrogate key - Superkey
Database normalization | Referential integrity | Relational DBMS | Distributed DBMS | ACID

Objects
Trigger | View | Table | Cursor | Log | Transaction | Index | Stored procedure | Partition
Topics in SQL
Select | Insert | Update | Merge | Delete | Join | Union | Create | Drop
Comparison of syntax

Implementations of database management systems
Types of implementations
Flat file | Deductive | Dimensional | Hierarchical | Object oriented | Temporal

Products
dBASE | Oracle | Sybase | MySQL | Microsoft SQL Server | PostgreSQL | DB2 | Comparison - relational | Comparison - object-relational
Components
Query language | Query optimizer | Query plan | ODBC | JDBC
Lists
List of object-oriented database management systems
List of relational database management systems
List of truly relational database management systems

 


From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.

Search Titles
0123456789
ABCDEFGHIJ
KLMNOPQRST
UVWXYZ?

E-mail this article to:

Personal Message: