ByteBoard Notes Notes

Delete the details of a student in the student table

Informatics Practices XII · Experiment 25 of 38 · SQL

★ CBSE suggested12-IPSQL queries
Expt. No.25
Page No.50

Delete a student

Aim

To delete the record of a student from the STUDENT table and display the remaining records.

Concepts used

Queries

USE school;DELETE FROM student WHERE sid = 2;SELECT * FROM student;

A marked line continues the line above it. In your file, write it on the same line.

Table used

Table: student
+-----+-------+-------+
| sid | name  | marks |
+-----+-------+-------+
|   1 | Asha  |    82 |
|   2 | Rohan |    67 |
|   3 | Ira   |    88 |
|   4 | Kabir |    91 |
|   5 | Diya  |    74 |
+-----+-------+-------+

Output

mysql> USE school; Database changed
mysql> DELETE FROM student WHERE sid = 2; Query OK, 1 row affected
mysql> SELECT * FROM student; +-----+-------+-------+ | sid | name | marks | +-----+-------+-------+ | 1 | Asha | 82 | | 3 | Ira | 88 | | 4 | Kabir | 91 | | 5 | Diya | 74 | +-----+-------+-------+ 4 rows in set

✓ Printed by running this query set, not typed by hand.

Result

Rohan's record (sid 2) was deleted ("1 row affected"), and 4 students remained.

Viva voce: what the examiner may ask

01What does DELETE without WHERE do?

It deletes every row of the table.

02Is DELETE a DDL or DML command?

DML: it changes data, not structure.

03How is DELETE different from DROP TABLE?

DELETE removes rows; DROP TABLE removes the table itself.

Variations for the lab test

  1. Delete students who scored below 70.
  2. Delete the student named Kabir.
  3. Delete all rows and check that the table still exists with DESCRIBE.
! Common mistake Writing DELETE sid = 2 FROM student or DELETE * FROM student is a syntax error.
Back to the 12-IP index