Hello I'm trying to disable all foreign key constraints on a database as I'm loading in some data. As it's part of a monthly job I want to do it dynamically so it can handle any changes. I'm trying to do this without using a cursor or temp table. I have built the statement below but so far this only creates an alter statement whereas I want it to execute the alter statement
declare @SQLStatement as nvarchar(4000)
SET @SQLStatement = 'exec (''select ''''alter table prpcref_mjp'''' + ''''.'''' + b.name + ''''.'''' + parent_tbl.name + '''' NOCHECK CONSTRAINT '''' + fk.name
from prpcref_mjp.sys.foreign_keys fk
inner join prpcref_mjp.sys.all_objects parent_tbl
on fk.parent_object_id = parent_tbl.object_id
inner join prpcref_mjp.sys.schemas b
on fk.schema_id = b.schema_id'')'
EXECUTE sp_executesql @SQLStatement