declare @sDelete varchar(2000) declare @Col varchar(50) --共同的字段 declare @sWhere varchar(2000) set @sWhere= 条件 declare cs_Table cursor for select sysobjects.[name] from syscolumns,sysobjects where sysobjects.[id]=syscolumns.[id] and sysobjects.xtype='U' and syscolumns.[name]=@Col open cs_Table fetch next from cs_Table into @Col while (@@FETCH_STATUS = 0) begin set @sDelete = 'delete from ' + @Col + ' where ' + @sWhere exec(@sDelete) fetch next from cs_Table into @Col end
对上进行修改,上面的好像没有表名 出现:delete from declare @zd varchar(10) , @name varchar(20) , @where varchar(100) , @sql varchar(8000) set @zd='si_id' ------相同字段 set @where='' ------条件 declare kk cursor for select a.name from sysobjects a,syscolumns b where a.type='u' and a.id=b.id and b.name=''+@zd+'' open kk fetch next from kk into @name while @@fetch_status=0 begin set @sql='delete from '+@name+' where '+@zd+'='+@where exec(@sql) fetch next from kk into @name end close kk deallocate kk -----cai 学习!!!
declare @Col varchar(50) --共同的字段
declare @sWhere varchar(2000)
set @sWhere= 条件
declare cs_Table cursor for
select sysobjects.[name] from syscolumns,sysobjects
where sysobjects.[id]=syscolumns.[id] and sysobjects.xtype='U' and syscolumns.[name]=@Col
open cs_Table
fetch next from cs_Table into @Col
while (@@FETCH_STATUS = 0)
begin
set @sDelete = 'delete from ' + @Col + ' where ' + @sWhere
exec(@sDelete)
fetch next from cs_Table into @Col
end
, @name varchar(20)
, @where varchar(100)
, @sql varchar(8000)
set @zd='si_id' ------相同字段
set @where='' ------条件
declare kk cursor for
select a.name from sysobjects a,syscolumns b where a.type='u' and a.id=b.id and b.name=''+@zd+''
open kk
fetch next from kk into @name
while @@fetch_status=0
begin
set @sql='delete from '+@name+' where '+@zd+'='+@where
exec(@sql)
fetch next from kk into @name
end
close kk
deallocate kk
-----cai 学习!!!