Update records in SQL

We say that we update a record when we modify any of its values.

To modify one or more data in one or more records we use "update".


Basic syntax of update records in SQL:


 update TABLE NAME set FIELD = NEWVALUE;


We use "update" together with the name of the table and "set" together with the field to modify and its new value.


The change will affect all records.

For example, in our "users" table, we want to change the values ​​of all keys, to "RealMadrid":


update users set key = 'RealMadrid';


We can modify some records, for this we must establish selection conditions with "where".


For example, we want to change the value corresponding to the key of our user called "Federicolopez", we want as a new key "Boca", we need a condition "where" that affects only this record:


 update users set password = 'Mouth'

  where name = 'Federicolopez';


If Oracle does not find records that meet the "where" condition, a message indicates that no records were modified.


The conditions are not mandatory, but if we omit the "where" clause, the update will affect all records.

We can also update multiple fields in a single statement:


 update users set name = 'Marceloduarte', password = 'Marce'

  where name = 'Marcelo';


To do this we place "update", the name of the table, "set" next to the name of the field and the new value and separated by a comma, the other name of the field with its new value.

Comments

Popular posts from this blog

Data Consistency and Inconsistency - What is Difference

Cardinality in DBMS – max/minimum cardinality & examples

Relational Model in DBMS