1.使用存储过程,利用游标清理符合条件的所有表
CREATE PROC sp_clearTable
@PreTitle varchar(100)
AS
BEGIN
declare @trun_name varchar(8000)
declare name_cursor cursor for
select 'truncate table ' + name from sysobjects where xtype='U' AND name LIKE @PreTitle+ '%' 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
END
GO
@PreTitle varchar(100)
AS
BEGIN
declare @trun_name varchar(8000)
declare name_cursor cursor for
select 'truncate table ' + name from sysobjects where xtype='U' AND name LIKE @PreTitle+ '%' 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
END
GO