Skip to content

Instantly share code, notes, and snippets.

@robsonalves
Last active October 21, 2015 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robsonalves/1db91baa1a4c4d46ce0b to your computer and use it in GitHub Desktop.
Save robsonalves/1db91baa1a4c4d46ce0b to your computer and use it in GitHub Desktop.
Remover All Columns
declare @query varchar(max) = ''
DECLARE @Remove nvarchar(1000)
select 'ALTER TABLE '+ a.name + ' drop column ' + b.name + '' as Remove
into #temp
from sys.tables a
inner join sys.columns b on b.object_id = a.object_id
where b.name like '%ROW%'
declare cur cursor for
select Remove from #temp
open cur
fetch cur into @Remove
while @@FETCH_STATUS = 0
begin
execute sp_executesql @Remove
fetch cur into @Remove
end
CLOSE cur
DEALLOCATE cur
drop table #temp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment