text: IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Role' AND COLUMN_NAME='NumericId')
    BEGIN
      ALTER TABLE Role
        ADD NumericId bigint NULL
    END
  GO
  
  IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Role' AND COLUMN_NAME='NumericId' AND IS_NULLABLE = 'YES')
    BEGIN
      WHILE EXISTS (SELECT TOP 1 id FROM Role WHERE NumericId IS NULL ORDER BY ApplicationId, Name)
        BEGIN
          DECLARE @nid bigint = (SELECT ISNULL(MAX(NumericId), 0) FROM Role) + 1
  
          UPDATE Role SET NumericId = @nid WHERE id IN (SELECT TOP 1 id FROM Role WHERE NumericId IS NULL ORDER BY ApplicationId, Name)
        END
  
      ALTER TABLE Role
        ALTER COLUMN NumericId bigint NOT NULL
    END
  GO