Page 179 - trackpad v5.1 class 8 flipbook
P. 179
SELECT Marks FROM Student WHERE FirstName like 'D%'; +-------+
| Marks |
+-------+
| 480 |
UPDATING RECORDS IN A TABLE +-------+
Sometime, you may need to change the details inserted into a table. In that case, the UPDATE
command will work. The syntax of the UPDATE command is:
UPDATE table_name SET field_change=value WHERE field_criteria=value;
Let us change the marks of the student having 10002 as StudentID from 480 to 485 by using the
following command:
UPDATE Student SET Marks = 485 where StudentID = 10002;
+-----------+-----------+----------+-------+
| StudentID | FirstName | LastName | Marks |
+-----------+-----------+----------+-------+
| 10001 | Amit | Sharma | 450 |
| 10002 | Divya | Kaushik | 485 |
| 10003 | Aadarsh | Kumar | 475 |
+-----------+-----------+----------+-------+
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
We can remove a specific record by using the WHERE clause with the DELETE command. If we use
the DELETE 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:
DELETE FROM Student WHERE LastName="Kumar";
To remove all the records, following command is used:
DELETE FROM Student;
DROP command is used to delete the structure of a table or even the database.
Example:
To delete the table Student from database:
DROP TABLE student;
To delete the database School:
DROP DATABASE school;
Techipedia (MySQL) 177

