日期:2014-05-18 浏览次数:20493 次
SELECT 'DELETE FROM '+'['+NAME+'];' FROM SYSOBJECTS WHERE XTYPE='U' AND NAME LIKE 'TBBOOK%' AND NAME NOT IN(SELECT TBBOOK FROM tbcustomer WHERE TBBOOK IS NOT NULL)
------解决方案--------------------
declare @tablename varchar(100) declare @sql varchar(4000) declare @Num int declare tb_cursor scroll cursor for select name from sysobjects where xtype='U' AND NAME LIKE 'TBBOOK%' AND NAME NOT IN(SELECT TBBOOK FROM tbcustomer WHERE TBBOOK IS NOT NULL) open tb_cursor fetch next from tb_cursor into @tablename while @@fetch_status=0 begin set @sql=' delete from '+@tablename exec (@sql) fetch next from tb_cursor into @tablename end close tb_cursor deallocate tb_cursor
------解决方案--------------------