Deleting record from a parent table
-
Hi, i have a parent and child tables. when i am deleting a row from a parent table i want to check wheter that value in Primarykey column exits in childtables or not(it is a forien key in child tables) without mentioning the child table names.ie; i should be generic..i am using sqlserver 2005. Anu
-
Hi, i have a parent and child tables. when i am deleting a row from a parent table i want to check wheter that value in Primarykey column exits in childtables or not(it is a forien key in child tables) without mentioning the child table names.ie; i should be generic..i am using sqlserver 2005. Anu
Then you will have to write some SQL that examines the dependencies of a table, find the relationships then traverses it and examine the child table. You might be able to wrap this up into a UDF (User Defined Function) but I can't imagine that it would be very quick.
Upcoming FREE developer events: * Glasgow: db4o: An Embeddable Database Engine for Object-Oriented Environments, Mock Objects, SQL Server CLR Integration, Reporting Services ... My website
-
Hi, i have a parent and child tables. when i am deleting a row from a parent table i want to check wheter that value in Primarykey column exits in childtables or not(it is a forien key in child tables) without mentioning the child table names.ie; i should be generic..i am using sqlserver 2005. Anu
If you want it to prevent deletes if there are child rows, why not just make sure that cascading deletes is switched off on your tables?
Deja View - the feeling that you've seen this post before.
-
If you want it to prevent deletes if there are child rows, why not just make sure that cascading deletes is switched off on your tables?
Deja View - the feeling that you've seen this post before.
-
How can i switched of cascading deletes. actually i am not deleting the full record from parent table.just i want to check checking whether it contains child rows or not Anu
OK - the cascading ability is maintained per FK relationship. As you aren't actually performing a delete - you are only doing an update, you are going to have to do this the way that Colin suggested.
Deja View - the feeling that you've seen this post before.