Beginner Ques::How to delete records permanently in case of linked tables?

Posted by Serenity on Stack Overflow See other posts from Stack Overflow or by Serenity
Published on 2011-01-05T19:50:42Z Indexed on 2011/01/05 19:53 UTC
Read the original article Hit count: 149

Filed under:
|
|

Let's say I have these 2 tables QuesType and Ques:-

QuesType

QuestypeID|QuesType      |Active
------------------------------------
101       |QuesType1     |True
102       |QuesType2     |True
103       |XXInActiveXX  |False



Ques

QuesID|Ques|Answer|QUesTypeID|Active
------------------------------------
1     |Ques1|Ans1 |101     |True
2     |Ques2|Ans2 |102     |True
3     |Ques3|Ans3 |101     |True

In the QuesType Table:- QuesTypeID is a Primary key

In the Ques Table:- QuesID is a Primary key and QuesType ID is the Foreign Key that refernces QuesTypeID from QuesType Table

Now I am unable to delete records from QuesType Table, I can only make QuesType inactive by setting Active=False. I am unable to delete QuesTypes permanently because of the Foreign key relation it has with Ques Table. So , I just set the column Active=false and those Questypes then don't show on my grid wen its binded.

What I want to do is be able to delete any QuesType permamnently. Now it can only be deleted if its not being used anywhere in the Ques table, right?

So to delete any QuesType permanently I thot this is what I could do:-

In the grid that displays QuesTypes, I have this check box for Active and a button for delete.What I thot was, when a user makes some QuesType inactive then OnCheckChanged() event will run and that will have the code to delete all the Questions in Ques table that are using that QuesTypeID. Then on the QuesType grid, that QuesType would show as Deactivated and only

then can a user delete it permanently.

Am I thinking correctly?

Currently in my DeleteQuesType Stored Procedure what I am doing is:-

Setting the Active=false and Setting QuesTye= some string like XXInactiveXX

Is there any other way?

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET