﻿
 DISABLE TRIGGER ALL ON T_DICTIONARYITEMBASE;  
 EXEC [dev].[uspCreateDictionaryItems] NULL, NULL; 
 ENABLE TRIGGER ALL ON T_DICTIONARYITEMBASE;  
 DECLARE @torolsql nvarchar(max) = N''
SELECT @torolsql += N'
     UPDATE ' + rt.name + ' SET TOROLT = ''T''
     WHERE '+ rc.name +' between 8757 and 8768'
FROM sys.foreign_keys fk
	INNER JOIN sys.foreign_key_columns fkc ON fkc.constraint_object_id = fk.object_id
	INNER JOIN sys.tables rt ON fkc.parent_object_id = rt.object_id
	INNER JOIN sys.columns rc ON rc.column_id = fkc.parent_column_id AND rc.object_id =   rt.object_id
	INNER JOIN sys.columns c ON c.column_id = fkc.referenced_column_id AND c.object_id = fkc.referenced_object_id
	INNER JOIN sys.tables fkt ON fkt.object_id = fkc.referenced_object_id AND fkt.name = 'T_KepesitesTipus'
	INNER JOIN sys.columns ctanevId ON ctanevId.object_id = rt.object_id AND ctanevId.name IN (N'C_ALTANEVID',N'C_TANEVID') 
	WHERE rc.name NOT IN (N'C_ALINTEZMENYID', N'C_INTEZMENYID',N'C_ALTANEVID',N'C_TANEVID', 'ID')

EXEC sp_executesql @torolsql
