0

I would like to see on a specific table if the foreign keys are enabled. So to check which of the below options is enabled on a table in a ms-sql server?

It's enabled / disabled like this:

-- Disable the constraints on a table called tableName:
ALTER TABLE tableName NOCHECK CONSTRAINT ALL

-- Re-enable the constraints on a table called tableName:
ALTER TABLE tableName WITH CHECK CHECK CONSTRAINT ALL
---------------------------------------------------------

-- Disable constraints for all tables:
EXEC sp_msforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT all'

-- Re-enable constraints for all tables:
EXEC sp_msforeachtable 'ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all'
---------------------------------------------------------
BramscoChill
  • 383
  • 4
  • 17
  • whats the question? – Josh Stevens Jul 20 '18 at 08:27
  • huh, I thought I described my question pretty well. The code is an example to set the constraint checks, bud I want to see on an table which of those options is set. So for an table if the foreign keys are enabled or not? – BramscoChill Jul 20 '18 at 08:32

0 Answers0