Friday, 10 June 2011

SQL:Script for Drop All Foreign Key Constraints from Current Database

--Generate Script For Drop All Foreign Key Constraints From your Current Database
SELECT 'ALTER TABLE '+OBJECT_NAME(F.parent_object_id)+' DROP CONSTRAINT '+F.NAME FROM sys.foreign_keys F
Run the above Query.
Output-
ALTER TABLE BR_DTL DROP CONSTRAINT FK__BR_DTL__BR_PTCDALTER TABLE BR_DTL DROP CONSTRAINT FK__BR_DTL__BR_TNIDALTER TABLE COM_MST DROP CONSTRAINT FK__COM_MST__COM_TPC
Run the generated Above script
This Script will help you for Dropping all foreign key.Really, I was in trouble when my project Manager ask me for writing the query for Droping all Constraints and recreate.Really it was one of my one of the best effort to work with Database.I took the question of my project Manager and did it.


Posted By: Manoj K. Bardhan
Follow Link-http://javadevelopersguide.blogspot.com