select - How to clear all tables selected through a INFORMATION_SCHEMA.TABLES query in SQL? -
this question has answer here:
- sql server: delete rows of tables 4 answers
the result list of few hundred tables have useless rows should cleared. how can without manually typing each one?
not trying delete all tables, ones been selected through ,
declare @sql_string nvarchar(max) declare @tablename nvarchar(max) declare db_cursor cursor -- might want modify in order -- specific subset of tables select table_name information_schema.tables open db_cursor fetch next db_cursor @tablename while @@fetch_status = 0 begin set @sql_string = n'delete * ' + quotename(@tablename) exec sp_executesql @sql_string fetch next db_cursor @tablename end close db_cursor deallocate db_cursor something should trick.
as always, when deleting records in tables without where clause, careful.
Comments
Post a Comment