
/*------ ATD 405863 ------*/
DECLARE @nomePK varchar(50)
IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'OpICMRecolherLIF' and column_name = 'Filial')
begin
    ALTER TABLE OpICMRecolherLIF ADD Filial CHAR(2) not null default '  '

    EXECUTE('UPDATE OpICMRecolherLIF SET Filial = SPACE(2)')

    SELECT @nomePK = ISNULL(MAX(constraint_name),'')
            FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
            WHERE TABLE_NAME = 'OpICMRecolherLIF'
            AND OBJECTPROPERTY(OBJECT_ID(constraint_name), 'IsPrimaryKey') = 1

    EXECUTE('alter table OpICMRecolherLIF drop constraint ' + @nomePK)
    EXECUTE('alter table OpICMRecolherLIF add constraint PK_OPICMRECOLHERLIF primary key (Estado, Filial)')
end
go
