mysql> desc courses;
+--------------------+---------------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+---------------------------+------+-----+---------+----------------+
| course_id | int(11) | NO | PRI | NULL | auto_increment |
| course_name | varchar(50) | NO | UNI | NULL | |
| course_description | text | NO | | NULL | |
| course_added | datetime | NO | | NULL | |
| status | enum('Active','Inactive') | NO | | Active | |
+--------------------+---------------------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
mysql> desc papers;
+-------------------+---------------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+---------------------------+------+-----+---------+----------------+
| paper_id | int(11) | NO | PRI | NULL | auto_increment |
| course_id | int(11) | NO | | NULL | |
| paper_name | varchar(50) | NO | | NULL | |
| paper_description | text | NO | | NULL | |
| paper_added | datetime | NO | | NULL | |
| status | enum('Active','Inactive') | NO | | Active | |
+-------------------+---------------------------+------+-----+---------+----------------+
6 rows in set (0.00 sec)
mysql> desc question_sets;
+-----------------+---------------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+---------------------------+------+-----+---------+----------------+
| set_id | int(11) | NO | PRI | NULL | auto_increment |
| paper_id | int(11) | NO | | NULL | |
| set_name | varchar(100) | NO | | NULL | |
| set_description | text | NO | | NULL | |
| set_maxtime | time | NO | | NULL | |
| created_date | datetime | NO | | NULL | |
| status | enum('Active','Inactive') | NO | | Active | |
+-----------------+---------------------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)
mysql> desc questions;
+---------------+---------------------------------------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+---------------------------------------------------+------+-----+---------+----------------+
| question_id | int(11) | NO | PRI | NULL | auto_increment |
| set_id | int(11) | NO | | NULL | |
| question_text | varchar(50) | NO | | NULL | |
| option_1 | varchar(50) | NO | | NULL | |
| option_2 | varchar(50) | NO | | NULL | |
| option_3 | varchar(50) | NO | | NULL | |
| option_4 | varchar(50) | NO | | NULL | |
| answer | enum('option_1','option_2','option_3','option_4') | NO | | NULL | |
| status | enum('Active','Inactive') | NO | | Active | |
+---------------+---------------------------------------------------+------+-----+---------+----------------+
These are the four tables the table courses is connected papers table papers is connected to question_sets and question_set is connected to questions if i delete the course_id=1 in table "course" the row corresponds to course_id in table papers should get deleted and the row corresponds to the paper_id in table question_sets should get deleted and the row corresponds to the question_id in table questions should get delete i have tired the following query it deletes the records from the papers table is it possible to perform delete operation in all table single query??
delete from papers where course_id IN (select course_id from courses where course_id=7);
note:the above query deletes the row from paper table