Click here to Skip to main content
15,916,600 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I gave below one to re enable constrain
SqlCommand md=new SqlCommand("exec sp_MSforeachtable @command1 = 'print' '?', @command2 = 'ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all'",con);
md.ExecuteNonQuery();

But It Gave "incorrect syntax near '?'.


What I have tried:

I tried and searched in net but unable to find suitable result.
Posted
Updated 28-Jun-17 1:10am

1 solution

SQL
-- Disable Constraints at DB level
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'

-- Enable Constraints at DB level
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
 
Share this answer
 
Comments
vijay_bale 28-Jun-17 10:51am    
thanks. It Worked for me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900