This hack job will do the sp_rename. I tested on a couple quick views I made and renamed using SMSS and did the trick..probably not ideal.I suggest printing the @SQL before letting it execute to be sure (the exec statement is commented out below)Declare @SQL varchar(1000)Declare @wrong varchar(25), @right varchar(25) Set @SQL = ''Declare cView CURSOR FORSelect Table_Name,RTRIM(substring(VIEW_DEFINITION,13,charindex(' ',View_Definition,13)-charindex('AS',View_Definition,13)-3)) as CorrectNameFROM information_Schema.viewswhere view_definition not like '%'+table_name+'%'OPEN cView FETCH NEXT FROM cView INTO @wrong,@right WHILE @@Fetch_status = 0 BEGIN Select @SQL = 'sp_rename ' + char(39)+ @wrong + char(39) + ','+char(39) + RTRIM(@right) + char(39) --exec (@SQL) --will execute the statement Print @SQL --will print the executable Print @wrong + ' Corrected to: ' + @right FETCH NEXT FROM cView INTO @wrong,@right ENDClose cViewDeallocate cView--check the resultsSelect *FROM information_Schema.viewswhere view_definition not like '%'+table_name+'%'
Poor planning on your part does not constitute an emergency on my part.