w3reference home
SQL Tutorial


Bookmark and Share

Updating Data

The UPDATE statement is used to update or change the existing data in the database. The syntax of UPDATE statement is given below.
UPDATE table_name
SET column_name1 = value1, column_name2 = value2,....
WHERE some_column = some_value;
The above syntax is just one way to represent this statement. The "where" clause can contain any combination of operators and as many conditions as needed. The omition of the "where" clause causes all the records in the table to be updated since it's the "where" clause which specifies which records have to be updated. So be careful !!

Consider the Emp_Stats table that we had discussed earlier. The table is again given below:

emp_id salary benefits position
010 75000 15000 Manager
105 65000 15000 Manager
152 60000 15000 Manager
215 60000 12500 Manager
244 50000 12000 Staff
300 45000 10000 Staff
335 40000 10000 Staff
400 32000 7500 Entry-Level
441 28000 7500 Entry-Level

Have a look at the following query:

UPDATE Emp_Stats
SET salary = 80000
WHERE position = 'Manager' ;
This sets all the Manager's salary to 80000. The output of the above query is shown below:

emp_id salary benefits position
010 80000 15000 Manager
105 80000 15000 Manager
152 80000 15000 Manager
215 80000 12500 Manager
244 50000 12000 Staff
300 45000 10000 Staff
335 40000 10000 Staff
400 32000 7500 Entry-Level
441 28000 7500 Entry-Level

A word of caution: In case you forget to put the "where" clause, the value of "salary" in all the records would be set to "80000" and the original value will be lost. There is no way to restore the changes made. So be careful while using this command..!!
Code Validator
Learn FTP
Color finder
Link Checker
Free web designs
Coming soon!
Interview Questions...
'w3reference : Learn by examples ... Advanced to beginner's tutorials ...'
Ajax: AJAX tutorial1 | Apache: Apache HTTP Server | Restarting Apache | CSS: CSS Border | CSS Syntax | CSS Selector | CSS Comment | CVS: CVS Release | CVS Login | CVS Logout | CVS Annotate | Databases: Rolap Tutorial | OLAP Tutorial | OLTP Tutorial | data warehousing | Expect: HTML: html | Linux: Dot (.) conf files | Linux Mount Point | Linux Filesystem | SSH Tutorial | Linux Commands: cal | cat | cfdisk | chroot | MySQL: MySQL Commands | PHP: PHP Basics | PHP Variables | PHP Output (echo/print) | PHP String Concat | PL/SQL: PL/SQL Data Types | PL/SQL Control Structures | PL/SQL File Extensions | PL/SQL DBMS_OUTPUT package | Python: My first Python program | Shell: Starting Bash | Bash Redirection | Bash Pipes | Bash Variables | SQL: SQL Transactions | SQL Constraints | SQL Drop | SQL Union & Union All | SVN: svn architecture | SVN Repository | SVN Import | SVN Checkout | Tech: soap | Web Designing: Web Hosting | HTML/XHTML/CSS code validator | Learn FTP | Search Engine Optimization Tips | www: XML: XML vs HTML | XML Syntax | XML Tags, Elements and Attributes | XML Namespaces |
Sitemap | Disclaim | Privacy Policy | Contact | ©2007-2009 w3reference.com All Rights Reserved.