-- Step 1: create temp table
create table APPS_ASSETS_TEMP (
    ID binary(16) not null,
    APPID varchar(255) not null,
    CONTENT varbinary(MAX) not null,
    ENCODING varchar(255) not null,
    FRIENDLY_NAME varchar(255) not null,
    TAG varchar(255) not null,
    primary key (ID)
);

-- Step 2: Migrate date from old table to temp and cast binary(255) to binary(16)
insert into APPS_ASSETS_TEMP (ID, APPID, CONTENT, ENCODING, FRIENDLY_NAME, TAG)
select cast(ID as binary(16)), APPID, CONTENT, ENCODING, FRIENDLY_NAME, TAG
from APPS_ASSETS;

-- Step 3: Delete old table
drop table APPS_ASSETS;

-- Step 5: Rename temp table
exec sp_rename 'APPS_ASSETS_TEMP', 'APPS_ASSETS';

-- Step 6: re-create indices
create index app_assets_appid_idx on APPS_ASSETS (APPID);
create index app_assets_content_lookup_idx on APPS_ASSETS (TAG, ENCODING);