Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
how we can not delete item from database if that item are using in another place how we can
do with in our project give some help
Posted
Updated 13-Dec-13 0:38am
v3
Comments
Tom Marvolo Riddle 13-Dec-13 6:25am    
records in table?please see Manfred's answer

If you want to prevent a row in a table to be deleted if you still want to reference it from another table you'll have to set up a foreign key relationship between these two tables. Lets say rows in table Main have one or more records in table Details, then you need to establish a foreign key relation from table Main towards table Details. That way records in table Detail can only be deleted when they are no longer being referenced from any existing foreign key relation.

See here: Creating and Modifying FOREIGN KEY Constraints[^]

Regards,

— Manfred
 
Share this answer
 
v2
Comments
thatraja 13-Dec-13 8:20am    
5!
Solution 1 is the best one. Besides you should check the existence of referred data of the element(which need to be deleted).

Recently I have answered similar question, check it out.
Handle Delete from Grid view have 2 tables with relationships[^]

Besides, Don't delete records, Change the status of Rows. By that way, you could maintain backups & get more benefits like audit. Check the below answer, explained there
Sql Table.. How to do this?[^]
 
Share this answer
 
Comments
Manfred Rudolf Bihy 13-Dec-13 8:25am    
"check the existence of referred data"
This can be hard to almost impossible if not using FK relationships.

Cheers!

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