Could Not Drop Object Referenced by Foreign Key Constraint
Symptom
When you run the SP_DropTables job, the job fails and prompts the following error:
Could not drop object %table_name% because it is referenced by a foreign key constraint.
Cause
The affected tables reference the foreign key constraint preventing the SP_DropTables job from running correctly.
Resolution
Manually release the constraints for the affected tables.
- In SQL Server Management Studio, run the following line to output associated foreign key constraints. The example shows the
SA_SPAC_ActivityEventstable—replace it with the table mentioned in the error message.
EXEC sp_fkeys 'SA_SPAC_ActivityEvents'
- The results will contain the
FKTABLE_NAMEcolumn—run the following line to release the corresponding constraint. The example shows theSA_SPAC_ActivityEventsforeign key. Run the line with eachFKTABLE_NAMEspecified in the results.
DROP TABLE SA_SPAC_GroupMembershipChanges
- After releasing the constraints, rerun the SP_DropTables job.