Monday, May 20, 2019

Sql Server - drop synonyms from specific schema

declare @syn nvarchar(300)
declare @temp1 nvarchar(300)
declare read_cur cursor for select distinct name from sys.synonyms where is_ms_shipped = 0

open read_cur
fetch read_cur into @syn
while @@fetch_status = 0
begin
      --select read_cur into @temp1
      set @temp1='drop synonym '+@syn
      exec sp_executesql @temp1

      fetch read_cur into @syn
end
close read_cur
deallocate read_cur

No comments:

Post a Comment