adsense


Tuesday, 3 November 2015

SQL UPDATE QUERY PAGE 17

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button



SQL UPDATE QUERY






SQL UPDATE Query 


The SQL UPDATE Query is used to modify the existing records in a table. 
You can use WHERE clause with UPDATE query to update selected rows, 
otherwise all the rows would be affected. 
Syntax: 
The basic syntax of UPDATE query with WHERE clause is as follows: 
UPDATE table_name 
SET column1 = value1, column2 = value2...., columnN = valueN 
WHERE [condition]; 
You can combine N number of conditions using AND or OR operators. 
Example: 
Consider the CUSTOMERS table having the following records: 
+----+----------+-----+-----------+----------+ 
| ID | NAME     | AGE | ADDRESS   | SALARY   | 
+----+----------+-----+-----------+----------+ 
|  1 | Ramakrishna  |  32 | Ahmedabad |  2000.00 | 
|  2 | Mdhu sudhan rao   |  25 | Delhi     |  1500.00 | 
|  3 | Sai  |  23 | Kota      |  2000.00 | 
|  4 | Kishor  |  25 | Mumbai    |  6500.00 | 
|  5 | Ranjith    |  27 | Bhopal    |  8500.00 | 
|  6 | Abhi    |  22 | MP        |  4500.00 | 
|  7 | Kumar     |  24 | Indore    | 10000.00 | 
+----+----------+-----+-----------+----------+ 
Following is an example, which would update ADDRESS for 
a customer whose ID is 6: 
SQL> UPDATE CUSTOMERS 
SET ADDRESS = 'Pune' 
WHERE ID = 6; 
Now, CUSTOMERS table would have the following records: 
CHAPTER 17
17 
+----+----------+-----+-----------+----------+ 
| ID | NAME     | AGE | ADDRESS   | SALARY   | 
+----+----------+-----+-----------+----------+ 
|  1 | Ramakrishna  |  32 | Ahmedabad |  2000.00 | 
|  2 | Mdhu sudhan rao   |  25 | Delhi     |  1500.00 | 
|  3 | Sai  |  23 | Kota      |  2000.00 | 
|  4 | Kishor  |  25 | Mumbai    |  6500.00 | 
|  5 | Ranjith    |  27 | Bhopal    |  8500.00 | 
|  6 | Abhi    |  22 | Pune      |  4500.00 | 
|  7 | Kumar     |  24 | Indore    | 10000.00 | 
+----+----------+-----+-----------+----------+ 
If you want to modify all ADDRESS and SALARY column values 
in CUSTOMERS table, you do not need to use WHERE clause and 
UPDATE query would be as follows: 
SQL> UPDATE CUSTOMERS 
SET ADDRESS = 'Pune', SALARY = 1000.00; 
Now, CUSTOMERS table would have the following records: 
+----+----------+-----+---------+---------+ 
| ID | NAME     | AGE | ADDRESS | SALARY  | 
+----+----------+-----+---------+---------+ 
|  1 | Ramakrishna  |  32 | Pune    | 1000.00 | 
|  2 | Mdhu sudhan rao   |  25 | Pune    | 1000.00 | 
|  3 | Sai  |  23 | Pune    | 1000.00 | 
|  4 | Kishor  |  25 | Pune    | 1000.00 | 
|  5 | Ranjith    |  27 | Pune    | 1000.00 | 
|  6 | Abhi    |  22 | Pune    | 1000.00 | 
|  7 | Kumar     |  24 | Pune    | 1000.00 | 
+----+----------+-----+---------+---------+ 
  
  
SQL DELETE 


No comments: