
if  dbo.udf_Conv_CompareVersion (dbo.udf_DBM_VersionNumber(),9,0,0,0) < 0  -- if @FromVersion < 9.0
BEGIN

declare @pkname     sysname
       ,@colcount int
       
select @pkname = i.name
      ,@colcount = count(*) over()
  from sys.index_columns  c
  join sys.indexes        i   on i.object_id = c.object_id
                             and i.index_id  = c.index_id
where
      i.object_id = object_id('MwusDevicePatchStatus')
  and i.index_id  = 1   
  
--select  @pkname   as [@pkname]                           
--       ,@colcount as [@colcount]
       
if @colcount < 5 begin

    exec('alter table MwusDevicePatchStatus drop constraint ' + @pkname)
    exec('
alter table MwusDevicePatchStatus
    add constraint PK_MwusDevicePatchStatus 
        PRIMARY KEY (DeviceGuid, UpdateGuid, RevisionNumber, EventID, LastChangeTime)
    ')

end    
END

