if ( 0 = dbo.udf_Conv_DoesColumnExist ('MwusDevicePatchStatus','RowID')) 
begin 

    DECLARE @debug BIT
	set @debug = 0

    --SELECT @@NESTLEVEL AS [SELECT @@NESTLEVEL]
	declare @tran int 
	set @tran = @@trancount


	declare @Script nvarchar(1000) 
	set @Script = '7470_102-MR2_MwusDevicePatchStatus_10-RowID_Express.sql'
    IF @debug = 1 PRINT @Script

	declare @Step   nvarchar(1000) 
	set @Step = 'Start'

	begin try
  
	if @tran = 0    
	BEGIN TRANSACTION   


	    -- rename MwusDevicePatchStatus --> MwusDevicePatchStatus_102MR1
        SET @Step = ' exec [dbo].[DBM_Conv_rename_Table] MwusDevicePatchStatus to MwusDevicePatchStatus_102MR1'
        IF @debug = 1 PRINT @Step
        --------------------
        exec [dbo].[DBM_Conv_rename_Table]
	                                        @tablename          = 'MwusDevicePatchStatus'
                                           ,@newname            = null
                                           ,@suffix             =  '_102MR1'
                                           ,@RenamePK            = 1
                                           ,@DropDF              = 1
                                           ,@DropFK              = 1
                                           ,@DropPK              = 0
                                           ,@DropNCIndex         = 0
                                           ,@OnlyIfTable         = 0
                                           ,@NotIfNewNameExists  = 1
                                           ,@debug               = @debug

        IF @debug = 1 begin
             SET @Step = ' SELECT FROM MwusDevicePatchStatus_102MR1 '
             PRINT @Step
             ----
             EXEC ('SELECT ''MwusDevicePatchStatus_102MR1'' 
                        , *
                      FROM MwusDevicePatchStatus_102MR1')
        end

        -- create empty  MwusDevicePatchStatus  
        SET @Step = '  CREATE TABLE dbo.MwusDevicePatchStatus '
        IF @debug = 1 PRINT @Step
        --------------------         
        EXEC('
             CREATE TABLE dbo.MwusDevicePatchStatus
            (
                [DeviceGuid]        [UNIQUEIDENTIFIER]  NOT NULL,
                [UpdateGuid]        [UNIQUEIDENTIFIER]  NOT NULL,
                [RevisionNumber]    [INT]               NOT NULL,
                [EventID]           [SMALLINT]          NOT NULL,
                [LastChangeTime]    [DATETIME]          NOT NULL CONSTRAINT [DF_MwusDevicePatchStatus_LastChangeTime] DEFAULT  GETUTCDATE()
               ,RowID               INT NOT NULL IDENTITY(1,1)
               ,CONSTRAINT [PK_MwusDevicePatchStatus] PRIMARY Key Clustered  ([DeviceGuid], [UpdateGuid], RowID desc)
            )
        ')
       

	if @tran = 0  
		   COMMIT   
		---------------------------------
end try
---------------------
begin catch

    declare @ErrorMessage       nvarchar(max)
    set @ErrorMessage = [dbo].[udf_ErrorInfo_Script](@Script,@Step)

    if (XACT_STATE() != 0) 
	and @tran = 0  
		rollback transaction

    RaisError (@ErrorMessage,16,255)

end catch
end 
go








