DECLARE @TarifficationAttributeId INT       = 2424;
DECLARE @TarifficationAttributeEntityId INT = 2423;

IF NOT EXISTS (
	SELECT 1 
	FROM   [dbo].[TarifficationAttribute] 
	WHERE  [Id]       = @TarifficationAttributeId
)
    BEGIN
		-- Отключаем тригер
		IF EXISTS (
			SELECT 1 
			FROM   [sys].[triggers] 
			WHERE  [Name] = 'TarifficationAttribute_ON_SYNC_INSERT'
		) 
			DISABLE TRIGGER [dbo].[TarifficationAttribute_ON_SYNC_INSERT] 
			ON              [dbo].[TarifficationAttribute];

		-- Добавляем запись
        INSERT INTO TarifficationAttribute(
            [id],
            [EntityId],
            [Name],
            [Path],
            [TarifficationAttributeTypeCode],
            [TarifficationAttributeTypeGroupVersionId],
            [AreaId],
            [CreateDate],
            [State],
            [DictionaryDate],
            [Product_Id],
            [IsDeleted]
        )
        VALUES(
            @TarifficationAttributeId,
            @TarifficationAttributeEntityId,
            'Юридическое лицо',
            'Basket.GetIsLegal()',
            'DealAttribute',
            1,
            1,
            GETDATE(),
            2,
            GETDATE(),
            14,
            0
        );

        -- Включаем тригер
        IF EXISTS (
			SELECT 1 
			FROM   [sys].[triggers] 
			WHERE  [Name] = 'TarifficationAttribute_ON_SYNC_INSERT'
		) 
			ENABLE TRIGGER [dbo].[TarifficationAttribute_ON_SYNC_INSERT]
			ON             [dbo].[TarifficationAttribute];
    END

DECLARE @ComponentTarifficationAttributeId INT       = 6116;
DECLARE @ComponentTarifficationAttributeEntityId INT = 6062;

IF NOT EXISTS (
	SELECT 1 
	FROM   [dbo].[ComponentTarifficationAttribute]
	WHERE  [Id] = @ComponentTarifficationAttributeId
)
    BEGIN
		-- Отключаем тригер
		IF EXISTS (
			SELECT 1
			FROM   [sys].[triggers]
			WHERE  [Name] = 'ComponentTarifficationAttribute_ON_SYNC_INSERT'
		) 
			DISABLE TRIGGER [dbo].[ComponentTarifficationAttribute_ON_SYNC_INSERT] 
			ON              [dbo].[ComponentTarifficationAttribute];
		
		-- Добавляем запись
        INSERT INTO ComponentTarifficationAttribute(
            [Id],
            [EntityId],
            [AreaId],
            [CreateDate],
            [State],
            [DictionaryDate],
            [TarifficationAttribute_Id],
            [IsDeleted]
        )
        VALUES(
            @ComponentTarifficationAttributeId,
            @ComponentTarifficationAttributeEntityId,
            1,
            GETDATE(),
            2,
            GETDATE(),
            @TarifficationAttributeId,
            0
        )
        -- Включаем тригер
        IF EXISTS (
			SELECT 1 
			FROM   [sys].[triggers]
			WHERE  [Name] = 'ComponentTarifficationAttribute_ON_SYNC_INSERT'
		) 
			ENABLE TRIGGER [dbo].[ComponentTarifficationAttribute_ON_SYNC_INSERT]
            ON             [dbo].[ComponentTarifficationAttribute];
    END

DECLARE @CalculationComponentSettingId INT = 3003;
DECLARE @OldFormula NVARCHAR(MAX) = '{5002} + {5015} + {5030} + {5033} + {5035} + {5089} + {5493} + {5527}';
DECLARE @NewFormula NVARCHAR(MAX) = FORMATMESSAGE('if ({attr_Юридическое лицо} == true) {%s} else {%s}', @OldFormula, @OldFormula);

IF EXISTS (
	SELECT 1 
	FROM   [dbo].[CalculationComponentSetting] 
	WHERE  [Id] = @CalculationComponentSettingId
)
    BEGIN
        -- Обновляем значение формулы
        UPDATE [dbo].[CalculationComponentSetting]
        SET    [CalculationFormula] = @NewFormula
        WHERE  [Id] = @CalculationComponentSettingId
    END;

IF NOT EXISTS (
    SELECT 1 
    FROM [dbo].[CalculationComponentSettingComponentTarifficationAttribute] 
    WHERE 
	    [CalculationComponentSetting_id]     = @CalculationComponentSettingId 
    AND [ComponentTarifficationAttribute_Id] = @ComponentTarifficationAttributeId
)
    BEGIN
        INSERT INTO [dbo].[CalculationComponentSettingComponentTarifficationAttribute](
            [CalculationComponentSetting_id],
            [ComponentTarifficationAttribute_Id]
        )
        VALUES(
            @CalculationComponentSettingId,
            @ComponentTarifficationAttributeId
        )
    END

Расскажи как работает скрипт