当前位置:文档之家› 网上商城项目数据库表

网上商城项目数据库表

网上商城项目数据库表*****************************************************' 添加商品记录同步添加库存记录的触发器'*****************************************************IF EXISTS (SELECT name FROM sysobjects WHERE name = 'AddGoodsInfo' AND type = 'TR') DROP TRIGGER AddGoodsInfoGOCREATE TRIGGER AddGoodsInfo ON [dbo].[GoodsInfo]FOR INSERTASINSERT INTO GoodsSave select GoodsID,GoodsName,0,0,getdate(),getdate() from insertedGO' 删除商品记录同步删除库存记录的触发器'*****************************************************IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DelGoodsInfo' AND type = 'TR') DROP TRIGGER DelGoodsInfoGOCREATE TRIGGER DelGoodsInfo ON [dbo].[GoodsInfo]FOR DELETEASDELETE from GoodsSave where GoodsID = (SELECT GoodsID FROM deleted)GO'*****************************************************' 重新同步商品在库存表中的对应记录的存储过程'*****************************************************CREATE PROCEDURE BindGoodsToSave ASIF EXISTS (SELECT name FROM sysobjects WHERE name = 'GoodsSave' AND type = 'U') BEGINDROP TABLE GoodsSavecreate table GoodsSave (GoodsSaveID integer identity,GoodsID integer null,GoodsName nvarchar(100) null,SaveNum integer null default 0,SaveAddNum integer null default 0,SaveTime datetime null default getdate(),SaveAddTime datetime null default getdate(),constraint PK_GOODSSAVE primary key (GoodsSaveID))ENDELSEBEGINcreate table GoodsSave (GoodsSaveID integer identity,GoodsID integer null,GoodsName nvarchar(100) null,SaveNum integer null default 0,SaveAddNum integer null default 0,SaveTime datetime null default getdate(),SaveAddTime datetime null default getdate(),constraint PK_GOODSSAVE primary key (GoodsSaveID))ENDINSERT INTO GoodsSave(GoodsID,GoodsName) select GoodsID,GoodsName from GoodsInfo order by GoodsID'*****************************************************' 按日期和月份统计注册人数的存储过程'*****************************************************CREATE procedure GetRegUsers@id intASdeclare @table table(ID int IDENTITY(1,1),RegDate nvarchar(10),RegNum int) declare @tempId int --临时表记录IDdeclare @tempRegDate nvarchar(10) --临时表日期set nocount onif (@id = 0)begininsert into @table(RegDate)select distinct convert(char(10),UserCreateTime,120) from Users order by convert(char(10),UserCreateTime,120) descdeclare _cursor cursor for select Id,RegDate from @tableopen _cursorfetch next from _cursor into @tempId,@tempRegDatewhile @@fetch_status = 0beginupdate @table set RegNum=(select count(UserID) from Users whereconvert(char(10),UserCreateTime,120) = @tempRegDate)where ID = @tempIdfetch next from _cursor into @tempId,@tempRegDateendclose _cursordeallocate _cursorendelsebegininsert into @table(RegDate)select distinct convert(char(7),UserCreateTime,120) from Users order by convert(char(7),UserCreateTime,120) descdeclare _cursor cursor for select Id,RegDate from @tableopen _cursorfetch next from _cursor into @tempId,@tempRegDatewhile @@fetch_status = 0beginupdate @table set RegNum=(select count(UserID) from Users whereconvert(char(7),UserCreateTime,120) = @tempRegDate)where ID = @tempIdfetch next from _cursor into @tempId,@tempRegDateendclose _cursordeallocate _cursorset nocount offselect * from @table where RegDate is not nullGO'*****************************************************' 按日期和月份统计用户订单的存储过程'*****************************************************CREATE procedure GetUserOrders@id intASdeclare @table table(ID int IDENTITY(1,1),RegDate nvarchar(10),RegNum int) declare @tempId int --临时表记录IDdeclare @tempRegDate nvarchar(10) --临时表日期set nocount onif (@id = 0)begininsert into @table(RegDate)select distinct convert(char(10),OrderTime,120) from GoodsOrder order by convert(char(10),OrderTime,120) descdeclare _cursor cursor for select Id,RegDate from @tableopen _cursorfetch next from _cursor into @tempId,@tempRegDatewhile @@fetch_status = 0beginupdate @table set RegNum=(select count(UserID) from GoodsOrder where convert(char(10),OrderTime,120) = @tempRegDate)where ID = @tempIdfetch next from _cursor into @tempId,@tempRegDateendclose _cursordeallocate _cursorendbegininsert into @table(RegDate)select distinct convert(char(7),OrderTime,120) from GoodsOrder order by convert(char(7),OrderTime,120) descdeclare _cursor cursor for select Id,RegDate from @tableopen _cursorfetch next from _cursor into @tempId,@tempRegDatewhile @@fetch_status = 0beginupdate @table set RegNum=(select count(UserID) from GoodsOrder where convert(char(7),OrderTime,120) = @tempRegDate)where ID = @tempIdfetch next from _cursor into @tempId,@tempRegDateendclose _cursordeallocate _cursorendset nocount offselect * from @table where RegDate is not nullGO。

相关主题