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

--Добавление записей:
CREATE TRIGGER [dbo].[T_PLAN_SECTION_ForUpdate] ON [dbo].[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'dbo.T_' + t2.EntName + '.' +  t01.SectionAlias,
				t1.SectionAlias AS [NEWName]

				FROM inserted t1
				JOIN deleted t01 on t01.PlanSectionID = t1.PlanSectionID
				JOIN T_ENTITIES t2 on t2.EntityID in (541, 546, 549, 563, 535, 536, 519, 571)
				LEFT JOIN T_ENTITIES t3 on t3.EntityID = t1.Entities
				LEFT JOIN T_ADDITIONAL_ENTITIES t4 on t4.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