Delete all data from SQL table if it is in any relation with other table

  • If you directly delete data then an error show regarding foreign key then you should use this query

    this query will remove all relation then delete data then again create relation as same as previously


    --EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'


    --EXEC sp_MSForEachTable 'DELETE FROM Employee ' --Delete all data from all tables


    ----EXEC sp_MSForEachTable 'DROP TABLE ProjectProduct' --Delete all table from database


    --EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'


Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Popular Posts of the Week