0

I have two tables names as

1.tbl_testquestion (qu_id primary)

+-------+----------+--------+
| qu_id | question | status |
+-------+----------+--------+
| 1     | who      | 1      |
+-------+----------+--------+
| 2     | why      | 1      |
+-------+----------+--------+
| 3     | what     | 1      |
+-------+----------+--------+

2.tbl_testanswer (id_answer primary)

(qu_id is from tbl_testquestion which is primary in that table)

+-----------+-------+--------+----------------+--------+
| id_answer | qu_id | answer | correct_answer | status |
+-----------+-------+--------+----------------+--------+
| 1         | 1     | me     | 1              | 1      |
+-----------+-------+--------+----------------+--------+
| 2         | 1     | you    | 0              | 1      |
+-----------+-------+--------+----------------+--------+
| 3         | 1     | they   | 0              | 1      |
+-----------+-------+--------+----------------+--------+
| 4         | 1     | us     | 0              | 1      |
+-----------+-------+--------+----------------+--------+
| 5         | 2     | mark   | 0              | 1      |
+-----------+-------+--------+----------------+--------+
| 6         | 2     | chen   | 0              | 1      |
+-----------+-------+--------+----------------+--------+
| 7         | 2     | ben    | 1              | 1      |
+-----------+-------+--------+----------------+--------+
| 8         | 2     | kun    | 0              | 1      |
+-----------+-------+--------+----------------+--------+

So when i try to delete any record from table tbl_testquestion then all records should be get deleted i.e all records with same qu_id from tbl_testanswer

SO how can i add foreign key or some other ..?

asif
  • 279
  • 3
  • 19

0 Answers0