How To Update A Table

Table of contents:

How To Update A Table
How To Update A Table

Video: How To Update A Table

Video: How To Update A Table
Video: SQL Tutorial - 21: The UPDATE Query 2024, May
Anonim

The table is one of the main elements of the database, which contains the main information. All other database objects are built on the basis of tables, such as queries, reports, etc.

How to update a table
How to update a table

Necessary

skills in working with MySql

Instructions

Step 1

Use the Update command to update the records in the tables. You can build this command as follows: Update, then enter the required parameters for updating the database table.

Step 2

Set the priority of this command, for example, Low_priority is set when updating the table will be delayed until other scripts finish working with the table.

Step 3

If necessary, set the Ignore parameter, if the table has unique fields and a duplicate value appears during update, then the command will not complete and these values will not change.

Step 4

Enter a name for the table, for this use the Tbl_name parameter. Then set the keyword Set, after that add the list of fields to be updated, as well as the updated field values themselves in the following form: Set "Enter the field name" = 'value'. For example, to update the Country field in all records of the Users table, run the command: Update ‘users’ set ‘country’ = ‘USA’. If the new value assigned by the Update command is similar to the old one, then this field will not be updated.

Step 5

Use the following example to increase the age of all users listed in the table by one year: Update ’users’ Set ‘age’ = ‘age’ + 1. In the same way, you can perform any arithmetic operation with the numeric values of the table, i.e. update data using multiplication, division, subtraction or addition.

Step 6

Use the Where parameter to specify the selection criteria for the records to be modified. In order to set the maximum number of mutable lines, use the Limit parameter. For example, you can update the first five records in a table with the following command: Update 'users ’Set‘ age ’=‘ age ’+1 Limit 5.

Recommended: