[存储过程] 利用存储过程

发布时间:2010年01月27日      浏览次数:706 次
利用存储过程来消除数据库中冗余的数据
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]=@pro
delete from mytest where [product]=@pro
insert into mytest ([product],[cost]) values(@pro,@mm)
fetch next from wu into @pro
end
close wu
deallocate wu
GO
我们可以使用作业进行相应的数据的更新
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!