IF INDEXPROPERTY(Object_Id('ISZL.T_INSURED_POLICY_RECORD'), 'IX_T_INSURED_POLICY_RECORD_fio', 'IndexID') Is Not Null
BEGIN
    DROP INDEX [IX_T_INSURED_POLICY_RECORD_fio] ON [ISZL].[T_INSURED_POLICY_RECORD]
END
IF INDEXPROPERTY(Object_Id('ISZL.T_INSURED_POLICY_RECORD'), 'IX_T_INSURED_POLICY_RECORD_Insured', 'IndexID') Is Not Null
BEGIN
    DROP INDEX [IX_T_INSURED_POLICY_RECORD_Insured] ON [ISZL].[T_INSURED_POLICY_RECORD]
END
IF INDEXPROPERTY(Object_Id('ISZL.T_INSURED_POLICY_RECORD'), 'IX_T_INSURED_POLICY_RECORD_Policy', 'IndexID') Is Not Null
BEGIN
    DROP INDEX [IX_T_INSURED_POLICY_RECORD_Policy] ON [ISZL].[T_INSURED_POLICY_RECORD]
END

IF (OBJECT_ID(N'[ISZL].[INSURED_POLICY_RECORD_fio]') IS NOT NULL)
begin
	DROP TRIGGER [ISZL].[INSURED_POLICY_RECORD_fio]
end
GO

IF EXISTS (SELECT * FROM sys.columns 
           WHERE object_id = OBJECT_ID('ISZL.T_INSURED_POLICY_RECORD') 
           AND name = 'FIO')
BEGIN
    ALTER TABLE ISZL.T_INSURED_POLICY_RECORD DROP COLUMN FIO;
END

ALTER TABLE [ISZL].[T_INSURED_POLICY_RECORD]
ADD FIO AS 
	CAST (
		UPPER(
			REPLACE(LastName + CHAR(160) + FirstName + isnull(CHAR(160) + Patronymic, CHAR(160)), 'ё', 'е')
		) AS VARCHAR(122)
	) PERSISTED
GO

CREATE INDEX [IX_T_INSURED_POLICY_RECORD_fio] ON [ISZL].[T_INSURED_POLICY_RECORD] ([FIO]);