DECLARE @typeName NVARCHAR(128);
SELECT
    @typeName = t.[name]
FROM [sys].[columns] AS c
INNER JOIN [sys].[types] AS t ON t.[user_type_id] = c.[user_type_id]
WHERE c.[object_id] = OBJECT_ID(N'[dbo].[Attachment]') AND c.[name] = N'AttachmentData';
IF @typeName = N'image'
    ALTER TABLE [dbo].[Attachment] ALTER COLUMN [AttachmentData] VARBINARY(MAX) NULL;