Domanda

Is there an easy way to test whether the primary key of a record is referenced in any other table in the database without going and searching for said primary key in all the applicable tables?

I want to know before I get to the exception, and disable a delete button.

È stato utile?

Soluzione

The way I normally deal with this foreign keys and references are by using EXISTS (Transact-SQL). By doing it this way, you have to use one EXISTS for every foreign key you want to check.

Another way of dealing with it is just to catch the exception and handling it in the code.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top