IF EXISTS
(
  SELECT 1 FROM SysObjects WITH (NOLOCK) JOIN SysColumns WITH (NOLOCK) 
    ON SysColumns.Id = SysObjects.ID AND SysColumns.Name = 'PrimaryType'
  WHERE SysObjects.Name = 'Universallog'
)
BEGIN
  UPDATE Universallog
  SET LINK = GuestNumber
  WHERE
    ISNULL(GUESTNUMBER, 0) > 0 AND
    ISNULL(LINK, 0) = 0 

  ALTER TABLE Universallog ALTER COLUMN UserID VARCHAR(50)
  ALTER TABLE Universallog ALTER COLUMN Description VARCHAR(100)
  ALTER TABLE Universallog DROP COLUMN PrimaryType
  ALTER TABLE Universallog DROP COLUMN Attachment
  ALTER TABLE Universallog DROP COLUMN GuestNumber

  DELETE FROM Universallog
  WHERE ISNULL(Link, 0) = 0
END
GO
