Page 335 - IT 402 v2.0 class 10
P. 335
+ - - - - - - +
| CO ST |
+ - - - - - - +
| 2 0 |
| 1 0 |
| 4 5 |
| 1 2 0 |
| 3 0 |
+ - - - - - - +
UPDATING RECORDS IN A TABLE
Sometime, you may need to change the detail inserted into a table. In that case, the UPDATE command will
work. The syntax of the UPDATE command is:
table name S field change value field criteria value
Let us change the marks of the student having 10002 as StudentID from 480 to 485 by using the following
command:
U P D AT E Stu d ent SE T M ar k s = 4 8 5 w her e Stu d entI D = 1 0 0 0 2 ;
+ - - - - - - - - - - - + - - - - - - - - - - - + - - - - - - - - - - + - - - - - - - +
| Stu d entI D | F ir stName | L astName | M ar k s |
+ - - - - - - - - - - - + - - - - - - - - - - - + - - - - - - - - - - + - - - - - - - +
| 1 0 0 0 1 | Amit | Shar ma | 4 5 0 |
| 1 0 0 0 2 | D iv y a | K au shik | 4 8 5 |
| 1 0 0 0 3 | Aad ar sh | K u mar | 4 5 0 |
+ - - - - - - - - - - - + - - - - - - - - - - - + - - - - - - - - - - + - - - - - - - +
REMOVING RECORDS FROM A TABLE
The DELETE command is used to remove records from a table. The DELETE command can be used in two
ways:
Without WHERE clause With the WHERE clause
e can remove a specific record by using the clause with the command. If we use the
command without the WHERE clause, it will remove all the records from a table. Let us use the DELETE
command to remove the record of a student whose LastName is Kumar:
F OM Student astName umar
To remove all the records, following command is used:
DELETE FROM Student;
USING AGGREGATE FUNCTIONS WITH SELECT COMMAND
MySQL provides the following aggregate functions:
Function Description
It calculates the average of the values in the selected column.
O N It calculates the number of rows returned for a SELECT command.
M It calculates the maximum value from a column.
MIN It calculates the minimum value from a column.
S M It calculates the sum of the values in a specified column.
Introduction to MySQL 333

