query in unique an foriegn keys

srivalli

Well-known member
Joined
May 4, 2005
Messages
189
Programming Experience
Beginner
in sql server,
i created one master table.
in that table i have one primary key(say id).
in second table, i am using "id" as foriegn key.

now when i am deleting any row in master table ,if it is having any childs ,then it is throwing error that this row cannot be deleted in the back end

but when i am trying to delete that particular row from vb.net ,that row is bieng deleted
i dont want that
when i am trying to delete any row which is having any childs from vb.net then an error or say warning should be displayed saying that the particular row is having childs so first delete that child nodes
so what should i do

one more BIG doubt I am having is can i have more than one foriegn keys in a single table(this is the case when i am trying to use more than one masters in my form )
hope my question is clear
any queries welcome
thanks
 
I think it depends on how you set the relationship. I do not know what database are you using, but in MySQL, you can set ON DELETE and ON UPDATE to Cascade, Set Nul, No Action or Restrict.

If you want a warning to be displayed, then it is time or defensive programming. You need to check whether that particular field has any other fields related to it or not.

Most database server will allow you to have more than one foreigh key in one single table

Hope this helps
 
Back
Top