----------- Добавляем запись с таблицей, которую создали в irisCoefficientDB в таблицу TableObjectsDefinition ----------
declare @currentDate                        datetime = getdate()
declare @Table_K_Correction_FL_Name nvarchar(50) = 'Table_K_Correction_FL';

if not exists (select 1 from [dbo].[TableObjectsDefinition] where Name = @Table_K_Correction_FL_Name)
    begin
        -- Добавляем запись
        insert into	[dbo].[TableObjectsDefinition] (
            [Name],
            [Description],
            [Type],
            [CreationDate]
        )
        values (
            @Table_K_Correction_FL_Name,
            N'Таблица для определения поправочного коэффициента для ФЛ',
            1,
            @currentDate
        )
    end;

declare @TableObjectsDefinitionId int = (select Id 
                                         from TableObjectsDefinition 
                                         where Name = @Table_K_Correction_FL_Name)

									 
---------------------------------- добавляем записи в TableObjectsHeadersDefinition ---------------------------------- 
CREATE OR ALTER PROCEDURE tmp_AddTableObjectsHeadersDefinition
    @TableObjectsDefinitionId INT,
    @SystemName NVARCHAR(255),
    @Name NVARCHAR(255),
    @DataType INT
AS
BEGIN
    -- Проверяем, существует ли запись с указанными параметрами
    IF NOT EXISTS (
        SELECT 1 
        FROM [dbo].[TableObjectsHeadersDefinition]
        WHERE ObjectID = @TableObjectsDefinitionId AND SystemName = @SystemName
    )
    BEGIN
        -- Добавляем запись
        INSERT INTO [dbo].[TableObjectsHeadersDefinition] (
            [ObjectID],
            [Name],
            [SystemName],
            [DataType]
        )
        VALUES (
            @TableObjectsDefinitionId,
            @Name,
            @SystemName,
            @DataType
        )
    END
END

-- Вызов процедуры для каждой вставки
EXEC tmp_AddTableObjectsHeadersDefinition @TableObjectsDefinitionId, 'CashbookIDPartner', N'CashbookID', 1;
EXEC tmp_AddTableObjectsHeadersDefinition @TableObjectsDefinitionId, 'BranchCode', N'Филиал', 2;
EXEC tmp_AddTableObjectsHeadersDefinition @TableObjectsDefinitionId, 'IsProlongation', N'Пролонгация', 1;
EXEC tmp_AddTableObjectsHeadersDefinition @TableObjectsDefinitionId, 'ChannelGroup', N'Группа КП', 2;
EXEC tmp_AddTableObjectsHeadersDefinition @TableObjectsDefinitionId, 'Channel', N'Канал продаж', 2;
EXEC tmp_AddTableObjectsHeadersDefinition @TableObjectsDefinitionId, 'NewTS', N'Новый авто', 1;
EXEC tmp_AddTableObjectsHeadersDefinition @TableObjectsDefinitionId, 'Brand', N'Марка авто', 2;
EXEC tmp_AddTableObjectsHeadersDefinition @TableObjectsDefinitionId, 'Model', N'Модель авто', 2;
EXEC tmp_AddTableObjectsHeadersDefinition @TableObjectsDefinitionId, 'K_Correction_FL', N'Коэффициент ФЛ', 3;

DROP PROCEDURE tmp_AddTableObjectsHeadersDefinition
GO
------------------------------------------------------------------------------------------------------------------------

--------------------------------------- Добавляем записи в StructureDefinition -----------------------------------------

--------------------------
DECLARE @sdversionId INT = (SELECT MAX(Id) FROM StructureDefinitionDictionariesVersion);
DECLARE @currentDate datetime = GetDate()

CREATE PROCEDURE tmp_AddStructureDefinition]
    @structureDefinitionId INT,
    @structureDefinitionEntityId INT,
    @tarifficationAttributeName NVARCHAR(255),
    @coefficientColumnName VARCHAR(50),
    @currentDate DATETIME,
    @sdversionId INT
AS
BEGIN
    -- Связка по имени коэффициента
    DECLARE @tariffTableId_K_Correction_FL INT = (SELECT TOP 1 ID FROM TariffTable WHERE SystemName = 'Table_K_Correction_FL');
    
    -- Связка по имени атрибута
    DECLARE @tarifficationAttributeId_Key INT = (SELECT TOP 1 ID FROM TarifficationAttribute WHERE Name = @tarifficationAttributeName);

    -- Отключение триггера, если он существует
    IF EXISTS (SELECT 1 FROM sys.triggers WHERE Name = 'StructureDefinition_ON_SYNC_INSERT')
        DISABLE TRIGGER [dbo].[StructureDefinition_ON_SYNC_INSERT] ON [dbo].[StructureDefinition];

    -- Проверка и вставка данных в таблицу StructureDefinition
    IF NOT EXISTS (SELECT 1 FROM StructureDefinition WHERE Id = @structureDefinitionId)
    BEGIN
        INSERT INTO StructureDefinition
            (Id, 
            EntityId, 
            ParameterName, 
            ParameterSystemName, 
            SortingOrder, 
            GroupingOrder, 
            ParameterTypeCode, 
            OperationTypeCode, 
            DataTypeCode, 
            TarifficationAttribute_Id, 
            TariffTable_Id, 
            CreateDate, 
            State, 
            DictionaryDate, 
            IsDeleted, 
            IsActual, 
            IsUpdated, 
            AreaId, 
            StructureDefinitionDictionariesVersionId)
        VALUES (
            @structureDefinitionId,
            @structureDefinitionEntityId,
            @tarifficationAttributeName,
            @coefficientColumnName, 
            2, 
            2, 
            'vertical', 
            'equal', 
            'integer', 
            @tarifficationAttributeId_Key, 
            @tariffTableId_K_Correction_FL,
            @currentDate, 
            2, 
            @currentDate, 
            0, 
            1, 
            0, 
            1, 
            @sdversionId
        );
    END

    -- Включение триггера, если он был отключен
    IF EXISTS (SELECT 1 FROM sys.triggers WHERE Name = 'StructureDefinition_ON_SYNC_INSERT')
        ENABLE TRIGGER [dbo].[StructureDefinition_ON_SYNC_INSERT] ON [dbo].[StructureDefinition];
END


-- @structureDefinitionId INT, @structureDefinitionEntityId INT, @tarifficationAttributeName NVARCHAR(255), @coefficientColumnName VARCHAR(50), @currentDate DATETIME, @sdversionId INT
EXEC tmp_AddStructureDefinition 2946, 2946, 'CashbookId', 'CashbookIDPartner',@currentDate, @sdversionId;
EXEC tmp_AddStructureDefinition 2947, 2947, 'Филиал', 'BranchCode',@currentDate, @sdversionId;
EXEC tmp_AddStructureDefinition 2948, 2948, 'Пролонгация', 'IsProlongation',@currentDate, @sdversionId;
EXEC tmp_AddStructureDefinition 2949, 2949, 'Группа КП', 'ChannelGroup',@currentDate, @sdversionId;
EXEC tmp_AddStructureDefinition 2950, 2950, 'Канал продаж', 'Channel',@currentDate, @sdversionId;
EXEC tmp_AddStructureDefinition 2951, 2951, 'Новое авто', 'NewTS',@currentDate, @sdversionId;
EXEC tmp_AddStructureDefinition 2952, 2952, 'Марка авто', 'Brand',@currentDate, @sdversionId;
EXEC tmp_AddStructureDefinition 2953, 2953, 'Модель авто', 'Model',@currentDate, @sdversionId;
EXEC tmp_AddStructureDefinition 2954, 2954, 'Коэффициент ФЛ', 'K_Correction_FL',@currentDate, @sdversionId;
GO



Что за ошибка?
 System.Exception: Script execution error 'C:\BuildAgent\work\16f9795aaf30b58\sources\App\src/Modules/iRIS.KaskoLink2/ChangeScripts\KaskoLink2.00033.LKA-2844.AddFLStructureDefinition.sql'.
12:47:00
    The variable name '@TableObjectsDefinitionId' has already been declared. Variable names must be unique within a query batch or stored procedure.
12:47:00
    Must declare the scalar variable "@SystemName".
12:47:00
    Must declare the scalar variable "@Name".