利用存儲過程來消除數據庫中冗余的數據 create procedure sp_mytest as declare @pro varchar(50) declare @mm int declare wu cursor for select distinct product from mytest open wu fetch next from wu into @pro while @@fetch_status=0 begin select @mm=sum([cost]) from mytest where [product][email protected] delete from mytest where [product][email protected] insert into mytest ([product],[cost]) values(@pro,@mm)
fetch next from wu into @pro end close wu deallocate wu go 我們可以使用作業進行相應的數據的更新