if exists (select * FROM sys.sysobjects where id = object_id(N'dbo.DepartmentHistory')) and not exists (select * FROM sys.sysobjects where id = object_id(N'dbo.RepositoryHistory'))
begin
    exec sys.sp_rename N'dbo.DepartmentHistory.IX_DepartmentHistory_DepartmentID', N'IX_RepositoryHistory_RepositoryID', N'INDEX';
    exec sys.sp_rename N'dbo.DepartmentHistory', N'RepositoryHistory';
    exec sys.sp_rename N'dbo.RepositoryHistory.DepartmentID', N'RepositoryID', N'COLUMN'
    exec sys.sp_rename N'dbo.PK_DepartmentHistory', N'PK_RepositoryHistory';
end