利用存储过程
2007-11-11 16:14:35 来源:WEB开发网核心提示: 利用存储过程来消除数据库中冗余的数据CREATE PROCEDURE sp_mytest ASdeclare @pro varchar(50)declare @mm intdeclare wu Cursor for select distinct product from mytes
利用存储过程来消除数据库中冗余的数据
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
我们可以使用作业进行相应的数据的更新
更多精彩
赞助商链接