Sunday, 29 March 2015

Drop multiple tables with string from database

declare @sql varchar(max)
declare @tablenames varchar(max)

select @tablenames = coalesce(@tablenames + ', ','') + Table_Name from INFORMATION_SCHEMA.TABLES    
where Table_Name like ('lg-010-%')

set @sql = 'drop table ' + @tablenames

exec (@sql)

No comments:

Post a Comment