Last active
October 21, 2015 15:57
-
-
Save robsonalves/1db91baa1a4c4d46ce0b to your computer and use it in GitHub Desktop.
Remover All Columns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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