ms sql 清库 语句,

declare @trun_name varchar(50)
declare name_cursor cursor for
select 'truncate table ' + name from sysobjects where xtype='U'
--此处是不需要清空的表
 and name not in('S_APR_TYPE','S_DROPDOWNLIST','S_TREEMENU',
'S_UPLOADIMG','S_PRODUCT_COLS','S_DefaultValue')
open name_cursor
fetch next from name_cursor into @trun_name
while @@FETCH_STATUS = 0
begin
  exec (@trun_name)
 print 'truncated table ' + @trun_name
 fetch next from name_cursor into @trun_name
end
close name_cursor
deallocate name_cursor


下面是原语句:

declare @trun_name varchar(50)
declare name_cursor cursor for
select 'truncate table ' + name from sysobjects where xtype='U' and status > 0
open name_cursor
fetch next from name_cursor into @trun_name
while @@FETCH_STATUS = 0
begin
  
exec (@trun_name)
 
print 'truncated table ' + @trun_name
 
fetch next from name_cursor into @trun_name
end
close name_cursor
deallocate name_cursor


来源:http://www.cnblogs.com/kingkoo/archive/2008/02/24/1079157.html

你可能感兴趣的:(C#)