Click here to Skip to main content
15,907,000 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have three tables Role,Master,Employee. Role have two columns Roleid and RoleName.

i used RoleId in Master and Emplyee. i want to delete One Row from Role. when i deletinb i want to check whether there is any record in other two tables with that deleting rows RoleID.

i am doing my project in asp.net

how can i do that?
Posted
Comments
King Fisher 29-May-14 5:13am    
Use Foreign key to avoid these Issues.

Hi,

Refer this Link[^]
 
Share this answer
 
Comments
CHill60 29-May-14 5:43am    
Nice link!
Shanalal Kasim 29-May-14 6:09am    
Thanks
Normally I would say set up your foreign keys with a cascade delete e.g. CASCADE in SQL Server with example[^] but beware which table you make the "parent" and which tables are "child" tables - I doubt you want to delete an Employee just because the Role disappears - you might want to reallocate them!

I thought about this again, and if your Role table is not the "parent" in the above context, but you want to change the other tables if a role is deleted, then you can create a Trigger on the Role table to be fired AFTER DELETE - an example can be found here http://www.tech-recipes.com/rx/41468/sql-server-coding-the-after-delete-trigger-in-sql-server/[^] and on CodeProject here - Triggers -- SQL Server[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900