IF  EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[FIES].[T_PLAN_SECTION_ForUpdate]'))
DROP TRIGGER [FIES].[T_PLAN_SECTION_ForUpdate]
GO

--Добавление записей:
CREATE TRIGGER [FIES].[T_PLAN_SECTION_ForUpdate] ON [FIES].[T_PLAN_SECTION]
FOR UPDATE 
AS
BEGIN

 SET NOCOUNT ON
	IF(UPDATE(SectionAlias))
	BEGIN

	     DECLARE @TABLE nvarchar(200),@COL2 nvarchar(100)
			/*Объявляем курсор*/
			DECLARE @CURSOR CURSOR
			/*Заполняем курсор*/
			SET @CURSOR  = CURSOR SCROLL
			FOR
				SELECT 
				N'FIES.T_' + t2.EntName + '.' +  t01.SectionAlias,
				t1.SectionAlias AS [NEWName]

				FROM inserted t1
				JOIN deleted t01 on t01.PlanSectionID = t1.PlanSectionID
				JOIN [VCLib].T_ENTITIES t2 on t2.EntName in ( 'PLAN_ITEM'
															, 'PLAN_ITEM_LIMITS'
															, 'SECTION_DEPEND_SETTINGS'
															, 'PLAN_REQUEST_SMO_ITEM'
															, 'SMO_COEF_MONTH_VALUES_EXCEPTION'
															, 'FACT_ITEM'
															, 'MEETING_RESOLVE'
															, 'SPLIT_SETTINGS'
															, 'FACT_ITEM_SUM'
															, 'EXTERNAL_PLAN_SUM'
															, 'COEFFICENT_STATINFO'
															, 'BASE_TARIFF'
															, 'MO_PARAMETER_ITEM'
															, 'TP_FIN_CLOSE_ITEM'
															, 'TP_TYPE'
															, 'PLAN_FACT_STATISTICS')
				LEFT JOIN [VCLib].T_ENTITIES t3 on t3.EntityID = t1.Entities
			/*Открываем курсор*/
			OPEN @CURSOR
			/*Выбираем первую строку*/
			FETCH NEXT FROM @CURSOR INTO @TABLE, @COL2
			/*Выполняем в цикле перебор строк*/
			WHILE @@FETCH_STATUS = 0
			BEGIN	    
				EXECUTE sp_rename  @TABLE, @COL2, 'COLUMN' 
			/*Выбираем следующую строку*/
			FETCH NEXT FROM @CURSOR INTO @TABLE, @COL2
			END
			CLOSE @CURSOR
			DEALLOCATE @CURSOR
    END

END