显示如银行账户一样的流水帐的sql server 设计 (请教了)

来源:互联网 发布:淘宝客人工服务电话 编辑:程序博客网 时间:2024/05/01 02:01

--这次建了视图

 CREATE TABLE ms(

 [fcid] [int] IDENTITY(1,1) primary key NOT NULL,--自增长ID

[m] [int] NULL CONSTRAINT [DF__member_money__m__0519C6AF] DEFAULT ((0)),--发生金额,收入时为正值,消费时为负值

 [d] [datetime] NULL,--日期时间

 [des] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,--摘要

 [mid] [int] NULL,--会员ID

 [ye] [int] NULL,--余额 )

 go

create proc pro_fc(@mid int,@m int,@des varchar(50)) as

 declare @d datetime

set @d =getdate()

 insert into ms(mid,m,d,des) values (@mid,@m,@d,@des)

  declare @i int

  set @i = 0;

  while(@i < 1000000)

  begin

     exec pro_fc 1001,1,'充值'

     exec pro_fc 1001,-1,'消费'

       set @i = @i +1

   end

 create view _fl_view as

    select mid as 会员ID,d as 时间,des as 摘要,m 金额,余额 = isnull(ye,(select sum(m) from ms b where fcid <= a.fcid and mid=a.mid )) from ms a

 

SET STATISTICS TIME ON

go

 select top 1000 * from _fl_view where 会员ID=1001

 GO 

  select * from _fl_view  where mid=1001

 SET STATISTICS TIME OFF;

--消息

 

 

SQL Server 执行时间: CPU 时间 = 0 毫秒,耗费时间 = 0 毫秒。 SQL Server 分析和编译时间: CPU 时间 = 16 毫秒,耗费时间 = 17 毫秒。 (所影响的行数为 1000 行) SQL Server 执行时间: CPU 时间 = 922 毫秒,耗费时间 = 961 毫秒。 SQL Server 分析和编译时间: CPU 时间 = 0 毫秒,耗费时间 = 0 毫秒。

 

原创粉丝点击