Sql Server - 从特定模式中删除同义词

时间:2014-09-26 05:59:48

标签: sql-server synonym

我想从特定架构中删除同义词,例如:

drop synonym where schema like 'my_schema'

drop synonym where name = my_schema.*

或者像这样的某些人? 有可能吗?

1 个答案:

答案 0 :(得分:1)

这应该做:

declare @syn nvarchar(30)
declare @temp1 nvarchar(30)
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