AND ArchivedTime is null OPEN relations FETCH NEXT FROM relations INTO @relation WHILE @fetch_status = 0 BEGIN - Rename columns ...

'
                  AND ArchivedTime is null
                  OPEN relations
                  FETCH NEXT FROM relations INTO @relation
                  WHILE @@fetch_status = 0
                  BEGIN
                  -- Rename columns
                  SET @tableChangeSql = N'EXEC sp_rename N''' + @relation + N'.[OtherActivityName]'', ''ReferenceName'', ''COLUMN'''
                  EXEC sp_executesql @tableChangeSql

                  SET @tableChangeSql = N'EXEC sp_rename N''' + @relation + N'.[OtherActivityID]'', ''ReferenceData'', ''COLUMN'''
                  EXEC sp_executesql @tableChangeSql

                  -- Add two new columns: ReferenceType and LongReferenceData
                  SET @tableChangeSql = N'ALTER TABLE ' + @relation + N' ADD ReferenceType NVARCHAR(128) DEFAULT N''BizTalkService'' WITH VALUES, LongReferenceData NTEXT NULL'
                  EXEC sp_executesql @tableChangeSql

                  -- Update ReferenceType to 'Activity' when OtherActivityName is not 'BizTalkOrchestration'
                  SET @tableChangeSql = N'UPDATE ' + @relation + N' SET ReferenceType = N''Activity'' WHERE ReferenceName <> N''BizTalkOrchestration'''
                  EXEC sp_executesql @tableChangeSql
                  
                  -- Update ReferenceType to 'BizTalkService' when OtherActivityName is 'BizTalkOrchestration'
                  -- Update ReferenceName to management server + management database + relationship
                  SET @tableChangeSql = N'UPDATE ' + @relation + N' SET ReferenceName = N''' + @ReferenceName + N''' WHERE ReferenceName = N''BizTalkOrchestration'''
                  EXEC sp_executesql @tableChangeSql

              FETCH NEXT FROM relations INTO @relation
          END

          CLOSE relations
          DEALLOCATE relations
          GO

          -- Place-holder, this will be modified in code
          ALTER VIEW
English
English (United States)
Deutsch (Deutschland)
German (Germany)
Español (España)
Spanish (Spain)
Français (France)
French (France)
日本語
Japanese
한국어
Korean