0
Your Cart
No products in the cart.

As the world continually changes, so does data. It is crucial for database languages (like SQL) to provide updated information saved in database systems. This is achieved through the SQL UPDATE command, which is an integral part of this pervasive query language.
SQL gives users the option to update existing records in tables with the help of the UPDATE command. Using this command, you can change and alter some (or all) of the records from single or multiple columns of a table. 
This is a vital command as the data in any dataset keeps changing, so it helps the user keep datasets up-to-date.
Let’s get an insight into the syntax of the UPDATE command.

Become an AI-powered Business Analyst

Purdue Post Graduate Program in Business AnalysisExplore Now
Become an AI-powered Business Analyst

UPDATE table_name
SET column_1=value_1, column_2=value_2,...
WHERE [condition];
NOTE: It is crucial to remember that without the WHERE clause, all records from the specified columns will be updated.
Let’s try to update the rows from a single column in a table.
For our example, we have a table that we’ll call “Employee,” as shown below: 
Employee_table
You can check this by using the DESC command.
Employee_details
As you can see, our table has the “Primary Key” constraint on the “EmployeeID” column, so it is important to remember not to update any records because it will create a duplicate value in this column. 
The “Name” column has a “NOT NULL” constraint on it, so we cannot update any of the rows to a NULL value in either of these two columns.
We’ll use the following query for this purpose:
one_column-SQL_UPDATE
We have enclosed the new “City” value in inverted commas since it is a character string data type—if not enclosed, the query will result in an error.
When executed, the query above will create the following table:
update_one_column_output
The photo above shows that the record has been updated from “Delhi” to “Chennai.”
For example, if all employees earning less than 30000 annually get raises, and their new salaries are now at 30000, we’ll use the following query to update these records in our table:
mysql-update
This will result in the following table:
emp-id.
These records have now been updated.
We will now update records from multiple table columns using a single query.
Sometimes, we need to change record values from different columns in a table, and we can use the UPDATE command for this purpose as well.
Updating_multiple_column-SQL_UPDATE

This will result in the following table:
/Updating_multiple_columns_output.
This shows that the columns have been updated.
For example, let’s see what happens when we try to update an employee's name as a NULL value.
null_constarint_erro
This results in an error because the “Name” column has a NOT NULL constraint specified on it.
The WHERE clause is an important part of the UPDATE command. Let’s see what happens if this clause is not present in the query.
We should always be cautious while using UPDATE in SQL, as without the WHERE clause, all column rows specified in the query are updated to the new value. This can cause a significant problem if done unintentionally. Let’s look at an example of this type of record updating.
If we want to update all the rows of the “City” and “Salary columns, in our “Employee” table to the values “Bangalore” and “50000”, respectively, we’ll use the following query:
update_all_records-SQL_UPDATE
This will result in the following table:
update_all_records_output
All records in these columns have been updated to the specified values.
We’ll use the following query for this purpose:
primary_key_error.
An error results, as the “EmployeeID” column is the Primary Key and cannot contain duplicate or NULL values.
With this, we come to the end of this article about the SQL UPDATE command.
It is crucial for datasets in database systems to stay up-to-date with the ever-changing, real-world data, and the UPDATE command in SQL enables users to do exactly that. You never have to worry about an outdated dataset. This command is a simple, yet powerful tool available to us.
Now that you know how to update existing records, it’s time for you to start querying and manipulating this updated and existing data in different datasets. This is an essential step to moving forward in your journey to becoming an SQL expert. If you liked this article, and want to get certified, check out Simplilearn’s Business Analyst Master’s Program. This comprehensive program covers SQL in-depth, and earning your certification in this field can help to jumpstart your career. 
Do you have any questions for us? Please leave them in the comments section, and we’ll have our experts in the field answer them for you.
Data Science & Business Analytics programs typically range from a few weeks to several months, with fees varying based on program and institution.
Cohort Starts: 5 Mar, 2024
Cohort Starts: 5 Mar, 2024
Cohort Starts: 12 Mar, 2024
Cohort Starts: 12 Mar, 2024
Cohort Starts: 25 Mar, 2024
Safeguarding the Digital Frontier Updated
Learn How to Add Column in SQL With Examples
The Ultimate Guide to Normalization in SQL
A Guide on How to Become a Site Reliability Engineer (SRE)
Working With Alter Command in SQL
What Is SQL Injection: How to Prevent SQL Injection
© 2009 -2024- Simplilearn Solutions
Follow us!
Company
Work with us
Discover
For Businesses
Learn On the Go!
Trending Post Graduate Programs
Trending Bootcamp Programs
Trending Master Programs
Trending Courses
Trending Categories
Trending Resources

source