September 20, 2019 at 3:12 pm
I have a parent table that is referenced by many other child tables . Is there a way to delete from this parent table with out dropping the foreign keys on other tables ? Right now I am doing the following steps, which involves dropping a lot of foreign keys.
exec sp_fkeys MainTable
--all the foreign keys are listed
--dropping all the foreign keys
--deleting from the parent table
--recreating the foreign keys
September 20, 2019 at 3:27 pm
you could set the foreign keys to cascade on delete
then all of your child objects would be deleted when you delete the parent row
MVDBA
September 20, 2019 at 3:29 pm
I want to keep the child data but just clear out the parent table.
September 20, 2019 at 3:31 pm
so you are having to put the FK back using WITH NOCHECK?
I can't really see why you have the foreign key in place (unless you are modifying their values to point to a different parent)
MVDBA
September 20, 2019 at 4:10 pm
I want to keep the child data but just clear out the parent table.
In that case, I would do a "soft" delete. That is, I would mark the parent record as being "deleted" without actually deleting it.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply