ALTER procedure [mig_director].[Export_SourceTable_SetLoadedExtension]
	@tableSchema varchar(128)
,   @tableName varchar(128)
,   @loadedCount int
as
	declare @date1 datetime2(7) = sysdatetime()
	declare @date2 datetime2(7) = dateadd(second, 1, @date1)

	declare @fileName varchar(512) = @tableSchema + '\' + @tableName + '.ExtensionLoad'

	declare @updated table([FullName] varchar(512))
	
	update [mig_director].[ExportSourceTable] 
	set 
		[LoadedCount] = @loadedCount
	,	[LoadedDate] = @date2
	output inserted.[FullName] into @updated
	where 
		[TableSchema] = @tableSchema
	and	[TableName] = @tableName

	if 0 < @@rowCount
	begin
		declare @fullName varchar(512) = (select top(1) [FullName] from @updated)

		delete [mig_director].[ExportSourceFile] 
		where 
			[FileName] = @fileName

		insert into [mig_director].[ExportSourceFile] (
			[FileName]
		,	[FullName]
		,	[FileDate]
		,	[SourceTableFullName]
		,	[DateOfLoadedFile]
		,	[LoadedDate]
		,	[LoadedCount]
		) values (
			@fileName
		,	@fileName
		,	@date1
		,	@fullName
		,	@date1
		,	@date1
		,	@loadedCount
		);
	end
